64bit / async-openai

Rust library for OpenAI
https://docs.rs/async-openai
MIT License
1.11k stars 166 forks source link

Update to Assistants example #146

Closed Strange-Knoll closed 9 months ago

Strange-Knoll commented 10 months ago

This example lets you chat with an assistant. It goes through the basic steps of sending queries, doing runs, and retrieving results.

64bit commented 10 months ago

Thank you for PR!

It requires a bit of updates - I left few comments.

64bit commented 10 months ago

I was able to review this today. There are bunch of warnings and requires a bit cleanup, do you mind taking a look please? I'd suggest leave the old example as it is and add this as a new example.

warning: unused imports: `ChatCompletionRequestSystemMessageArgs`, `CreateChatCompletionRequestArgs`, `CreateThreadAndRunRequestArgs`, `CreateThreadAndRunRequest`, `MessageContentTextObject`, `Role`, `config::OpenAIConfig`
 --> examples/assistants/src/main.rs:2:86
  |
2 | ...::{CreateMessageRequestArgs, CreateRunRequestArgs, CreateThreadRequestArgs, CreateThreadAndRunRequestArgs, CreateThreadAndRunRequest, CreateChatCompletionRequestArgs, ChatCompletionRequestSystemMessageArgs, Role, RunStatus, MessageContent, MessageContentTextObject, C...
  |                                                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  ^^^^                             ^^^^^^^^^^^^^^^^^^^^^^^^
3 | ...t, config::OpenAIConfig,
  |       ^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

warning: unreachable expression
   --> examples/assistants/src/main.rs:144:5
    |
39  | /     loop{
40  | |         println!("How can I help you?");
41  | |         //get user input
42  | |         let mut input = String::new();
...   |
142 | |         }
143 | |     }
    | |_____- any code following this expression is unreachable
144 |       Ok(())
    |       ^^^^^^ unreachable expression
    |
    = note: `#[warn(unreachable_code)]` on by default

warning: unreachable pattern
   --> examples/assistants/src/main.rs:136:17
    |
136 |                 _ => {
    |                 ^
    |
    = note: `#[warn(unreachable_patterns)]` on by default

warning: unused variable: `message_obj`
  --> examples/assistants/src/main.rs:52:13
   |
52 |         let message_obj = client
   |             ^^^^^^^^^^^ help: if this is intentional, prefix it with an underscore: `_message_obj`
   |
   = note: `#[warn(unused_variables)]` on by default
64bit commented 10 months ago

In addition few observations:

  1. perhaps README can be updated too. For example it helps for me or anyone looking at this example to just cargo run and copy paste the inputs from README.
  2. Ask user for deletion of assistant at the end of example?

Both are not required but good to have, makes it easier for anyone to run example and cleanup.

64bit commented 9 months ago

Hey this is well written example, I see you put great effort in writing README as well. Many many thanks!

Thank you for your patience too, this has been a long wait!