Comments (3)
400 with this:
#[tokio::test]
async fn test_stream() {
dotenv().ok();
let messages = match ChatCompletionRequestUserMessageArgs::default()
.content("Write a marketing blog praising and introducing Rust library async-openai")
.build()
{
Ok(msg) => msg.into(),
Err(e) => {
println!("Error: {}", e);
assert!(false);
return;
}
};
let client = Client::with_config(
OpenAIConfig::new()
.with_api_key(&std::env::var("MODEL_API_KEY").unwrap_or_default())
.with_api_base("https://api.perplexity.ai"),
);
let request = match CreateChatCompletionRequestArgs::default()
.model("mistralai/mixtral-8x7b-instruct")
.max_tokens(512u16)
.messages([messages])
.build()
{
Ok(req) => req,
Err(e) => {
println!("Error: {}", e);
assert!(false);
return;
}
};
let stream_result = client.chat().create_stream(request).await;
let mut stream = match stream_result {
Ok(s) => s,
Err(e) => {
println!("Error: {}", e);
assert!(false);
return;
}
};
let mut lock = stdout().lock();
while let Some(result) = stream.next().await {
match result {
Ok(response) => {
response.choices.iter().for_each(|chat_choice| {
if let Some(ref content) = chat_choice.delta.content {
write!(lock, "{}", content).unwrap();
}
});
}
Err(err) => {
writeln!(lock, "error: {err}").unwrap();
}
}
match stdout().flush() {
Ok(_) => (),
Err(e) => {
println!("Error: {}", e);
assert!(false);
return;
}
}
}
}
from async-openai.
interesting, using mistral api, different results:
#[tokio::test]
async fn test_stream() {
dotenv().ok();
let messages = match ChatCompletionRequestUserMessageArgs::default()
.content("Write a marketing blog praising and introducing Rust library async-openai")
.build()
{
Ok(msg) => msg.into(),
Err(e) => {
println!("Error: {}", e);
assert!(false);
return;
}
};
let client = Client::with_config(
OpenAIConfig::new()
.with_api_key(&std::env::var("MODEL_API_KEY").unwrap_or_default())
.with_api_base("https://api.mistral.ai/v1"),
);
let request = match CreateChatCompletionRequestArgs::default()
// .model("mistralai/mixtral-8x7b-instruct")
.model("mistral-tiny")
.max_tokens(512u16)
.messages([messages])
.build()
{
Ok(req) => req,
Err(e) => {
println!("Error: {}", e);
assert!(false);
return;
}
};
let stream_result = client.chat().create_stream(request).await;
let mut stream = match stream_result {
Ok(s) => s,
Err(e) => {
println!("Error: {}", e);
assert!(false);
return;
}
};
let mut lock = stdout().lock();
while let Some(result) = stream.next().await {
match result {
Ok(response) => {
response.choices.iter().for_each(|chat_choice| {
if let Some(ref content) = chat_choice.delta.content {
write!(lock, "{}", content).unwrap();
}
});
}
Err(err) => {
println!("Error: {}", err);
// jsonify error
let err = json!({
"error": err.to_string()
});
println!("error: {}", err);
writeln!(lock, "error: {err}").unwrap();
}
}
match stdout().flush() {
Ok(_) => (),
Err(e) => {
println!("Error: {}", e);
assert!(false);
return;
}
}
}
}
running 1 test
Error: failed to deserialize api response: missing fieldcreated
at line 1 column 154
error: {"error":"failed to deserialize api response: missing fieldcreated
at line 1 column 154"}
error: {"error":"failed to deserialize api response: missing fieldcreated
at line 1 column 154"}
Title: Unleashing Creativity and Productivity: An Introduction to async-openai, the Game-Changing Rust Library for Interacting with OpenAIAs technology continues to evolve at an unprecedented pace, developers are constantly on the lookout for tools that can help them build applications faster, more efficiently, and with greater creativity. One such tool that has been generating buzz in the Rust community is async-openai, an innovative library for interacting with OpenAI's powerful language models. In this blog post, we'll explore why async-openai is a must-have addition to any Rust developer's toolkit and how it can help you build AI-powered applications with ease.
First, let's talk about OpenAI. OpenAI is a leading artificial intelligence research laboratory, and its language models, such as the popular ChatGPT, have captured the imagination of people around the world with their ability to generate human-like text based on given prompts. Interacting with OpenAI's models, however, can be a complex and time-consuming process, especially for those who want to build applications that can leverage these models in real-time. This is where async-openai comes in.
async-openai is an asynchronous Rust library for interacting with OpenAI's models. Asynchronous programming is a programming paradigm that allows multiple tasks to be executed concurrently, which is essential for building high-performance applications. By using async-openai, Rust developers can easily integrate OpenAI's models into their applications, enabling real-time, responsive interactions with the models.
One of the key benefits of using async-openai is its simplicity. The library provides a straightforward and intuitive API for sending requests to OpenAI's models
from async-openai.
Related Issues (20)
- Tokenizer support HOT 3
- Missing names in ChatCompletionRequest[User, System, Assistant]Message
- Example of multiple function calls HOT 2
- how to change base_url? HOT 2
- text to speech - flac format does not seem to work HOT 9
- Auto Generation from OpenAPI spec HOT 3
- Add support for llama.cpp completions HOT 2
- impls.rs: AssistantTools HOT 3
- query for client files list seems to be missing HOT 1
- Why is there a \n\n prepended to the response? HOT 2
- Stabilizing wasm target HOT 2
- Support text-to-speech (TTS) streaming functionality HOT 12
- Advanced error handling for OpenAI-like LLM APIs
- Test compilation failed HOT 2
- Support variable length embeddings HOT 3
- OpenAI transcriptions api language field is invalid ! HOT 1
- Embedding deserialization error when using encoding_format `EncodingFormat::Base64`
- Ollama AI Chat Completion Example / OpenAI Compatibility HOT 3
- Sync OpenAPI spec changes after 4th Jan 24 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from async-openai.