11use openai_api_rs:: v1:: api:: OpenAIClient ;
2- use openai_api_rs:: v1:: chat_completion:: { self , ChatCompletionRequest } ;
2+ use openai_api_rs:: v1:: chat_completion:: {
3+ chat_completion:: ChatCompletionRequest , ChatCompletionMessage ,
4+ } ;
5+ use openai_api_rs:: v1:: chat_completion:: {
6+ Content , FinishReason , MessageRole , Tool , ToolChoiceType , ToolType ,
7+ } ;
38use openai_api_rs:: v1:: common:: GPT4_O ;
49use openai_api_rs:: v1:: types;
510use serde:: { Deserialize , Serialize } ;
@@ -32,16 +37,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3237
3338 let req = ChatCompletionRequest :: new (
3439 GPT4_O . to_string ( ) ,
35- vec ! [ chat_completion :: ChatCompletionMessage {
36- role: chat_completion :: MessageRole :: user,
37- content: chat_completion :: Content :: Text ( String :: from( "What is the price of Ethereum?" ) ) ,
40+ vec ! [ ChatCompletionMessage {
41+ role: MessageRole :: user,
42+ content: Content :: Text ( String :: from( "What is the price of Ethereum?" ) ) ,
3843 name: None ,
3944 tool_calls: None ,
4045 tool_call_id: None ,
4146 } ] ,
4247 )
43- . tools ( vec ! [ chat_completion :: Tool {
44- r#type: chat_completion :: ToolType :: Function ,
48+ . tools ( vec ! [ Tool {
49+ r#type: ToolType :: Function ,
4550 function: types:: Function {
4651 name: String :: from( "get_coin_price" ) ,
4752 description: Some ( String :: from( "Get the price of a cryptocurrency" ) ) ,
@@ -52,7 +57,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
5257 } ,
5358 } ,
5459 } ] )
55- . tool_choice ( chat_completion :: ToolChoiceType :: Auto ) ;
60+ . tool_choice ( ToolChoiceType :: Auto ) ;
5661
5762 // debug request json
5863 // let serialized = serde_json::to_string(&req).unwrap();
@@ -65,14 +70,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
6570 println ! ( "No finish_reason" ) ;
6671 println ! ( "{:?}" , result. choices[ 0 ] . message. content) ;
6772 }
68- Some ( chat_completion :: FinishReason :: stop) => {
73+ Some ( FinishReason :: stop) => {
6974 println ! ( "Stop" ) ;
7075 println ! ( "{:?}" , result. choices[ 0 ] . message. content) ;
7176 }
72- Some ( chat_completion :: FinishReason :: length) => {
77+ Some ( FinishReason :: length) => {
7378 println ! ( "Length" ) ;
7479 }
75- Some ( chat_completion :: FinishReason :: tool_calls) => {
80+ Some ( FinishReason :: tool_calls) => {
7681 println ! ( "ToolCalls" ) ;
7782 #[ derive( Deserialize , Serialize ) ]
7883 struct Currency {
@@ -90,10 +95,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
9095 }
9196 }
9297 }
93- Some ( chat_completion :: FinishReason :: content_filter) => {
98+ Some ( FinishReason :: content_filter) => {
9499 println ! ( "ContentFilter" ) ;
95100 }
96- Some ( chat_completion :: FinishReason :: null) => {
101+ Some ( FinishReason :: null) => {
97102 println ! ( "Null" ) ;
98103 }
99104 }
0 commit comments