88class Conversation
99{
1010 const END_CHAR = '<|endoftext|> ' ;
11+ const DEFAULT_MODEL = 'OpenAssistant/oasst-sft-6-llama-30b-xor ' ;
1112
1213 // Conversation IDs
1314 public $ id ;
@@ -17,13 +18,17 @@ class Conversation
1718 protected $ current_started ;
1819 protected $ current_text ;
1920
20- public function __construct ($ identifiers = null )
21+ public function __construct ($ identifiers = null , $ model = null )
2122 {
23+ if (is_null ($ model )) {
24+ $ model = self ::DEFAULT_MODEL ;
25+ }
26+
2227 if (is_array ($ identifiers ) && ! empty ($ identifiers ['cookie ' ]))
2328 $ this ->cookie = $ identifiers ['cookie ' ];
2429
2530 if (! is_array ($ identifiers ))
26- $ identifiers = $ this ->initConversation ();
31+ $ identifiers = $ this ->initConversation ($ model );
2732
2833 $ this ->id = $ identifiers ['id ' ];
2934 $ this ->cookie = $ identifiers ['cookie ' ];
@@ -37,20 +42,26 @@ public function getIdentifiers()
3742 ];
3843 }
3944
40- public function initConversation ()
45+ public function initConversation ($ model )
4146 {
4247 $ headers = [
4348 'method: POST ' ,
44- 'accept: application/json ' ,
45- "referer: https://huggingface.co/chat " ,
49+ 'accept: */* ' ,
50+ 'accept-language: en-US,en;q=0.9 ' ,
51+ 'accept-encoding: gzip, deflate, br ' ,
52+ "referer: https://huggingface.co/chat/ " ,
53+ "origin: https://huggingface.co " ,
4654 'content-type: application/json ' ,
55+ 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 ' ,
4756 ];
4857
4958 if (! empty ($ this ->cookie )) {
5059 $ headers [] = "cookie: hf-chat= {$ this ->cookie }" ;
5160 }
5261
53- list ($ data , $ request , $ url , $ cookies ) = Tools::request ("https://huggingface.co/chat/conversation " , $ headers , '' , true );
62+ $ data = json_encode (['model ' => $ model ]);
63+
64+ list ($ data , $ request , $ url , $ cookies ) = Tools::request ("https://huggingface.co/chat/conversation " , $ headers , $ data , true );
5465 $ data = json_decode ($ data , true );
5566
5667 if (! empty ($ cookies ['hf-chat ' ])) {
0 commit comments