Commit 906bf31 1 parent 43d6aad commit 906bf31 Copy full SHA for 906bf31
File tree 1 file changed +37
-1
lines changed
1 file changed +37
-1
lines changed Original file line number Diff line number Diff line change 1
- use crate :: models:: general:: llm:: Message ;
1
+ use crate :: models:: general:: llm:: { ChatCompletion , Message } ;
2
2
3
3
use dotenv:: dotenv;
4
4
use reqwest:: header:: { HeaderMap , HeaderValue } ;
@@ -30,4 +30,40 @@ pub async fn call_gpt(message: Vec<Message>) {
30
30
"OpenAI-Organization" ,
31
31
HeaderValue :: from_str ( & api_org. as_str ( ) ) . unwrap ( ) ,
32
32
) ;
33
+
34
+ //create client
35
+ let client = reqwest:: Client :: builder ( )
36
+ . default_headers ( headers)
37
+ . build ( )
38
+ . unwrap ( ) ;
39
+
40
+ // create chat completion
41
+ let chat_completion: ChatCompletion = ChatCompletion {
42
+ model : "gpt-3.5-turbo" . to_string ( ) ,
43
+ messages : message,
44
+ temperature : 0.1 ,
45
+ } ;
46
+
47
+ // Troubleshooting
48
+ let res_raw = client
49
+ . post ( url)
50
+ . json ( & chat_completion)
51
+ . send ( )
52
+ . await . unwrap ( ) ;
53
+
54
+ dbg ! ( & res_raw. text( ) . await . unwrap( ) ) ;
55
+ }
56
+
57
+ #[ cfg( test) ]
58
+ mod tests {
59
+ use super :: * ;
60
+ #[ tokio:: test]
61
+ async fn test_to_call_gpt ( ) {
62
+ let message = Message {
63
+ role : "user" . to_string ( ) ,
64
+ content : "hi this-is test. Give me a shot response" . to_string ( ) ,
65
+ } ;
66
+ let messages: Vec < Message > = vec ! [ message] ;
67
+ call_gpt ( messages) . await ;
68
+ }
33
69
}
You can’t perform that action at this time.
0 commit comments