프로젝트
GitHub에서 보기
openai-rs/openai-api
소개
복잡한 비동기 작업과 불필요한 의존성이 없는 간단한 OpenAI API용 Rust 라이브러리입니다.
AI 및 머신러닝측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalOpenAI API for Rust
A community-maintained library provides a simple and convenient way to interact with the OpenAI API. No complex async and redundant dependencies.
API
check official API reference
| API | Support |
|---|---|
| Models | ✔️ |
| Completions | ✔️ |
| Chat | ✔️ |
| Images | ✔️ |
| Embeddings | ✔️ |
| Audio | ✔️ |
| Files | ❌ |
| Fine-tunes | ❌ |
| Moderations | ❌ |
| Engines | ❌ |
Usage
Add the following to your Cargo.toml file:
openai_api_rust = "0.1.9"
Export your API key into the environment variables
export OPENAI_API_KEY=<your_api_key>
Then use the crate in your Rust code:
use openai_api_rust::*;
use openai_api_rust::chat::*;
use openai_api_rust::completions::*;
fn main() {
// Load API key from environment OPENAI_API_KEY.
// You can also hardcode through `Auth::new(<your_api_key>)`, but it is not recommended.
let auth = Auth::from_env().unwrap();
let openai = OpenAI::new(auth, "https://api.openai.com/v1/");
let body = ChatBody {
model: "gpt-3.5-turbo".to_string(),
max_tokens: Some(7),
temperature: Some(0_f32),
top_p: Some(0_f32),
n: Some(2),
stream: Some(false),
stop: None,
presence_penalty: None,
frequency_penalty: None,
logit_bias: None,
user: None,
messages: vec![Message { role: Role::User, content: "Hello!".to_string() }],
};
let rs = openai.chat_completion_create(&body);
let choice = rs.unwrap().choices;
let message = &choice[0].message.as_ref().unwrap();
assert!(message.content.contains("Hello"));
}
Use proxy
Load proxy from env
let openai = OpenAI::new(auth, "https://api.openai.com/v1/")
.use_env_proxy();
Set the proxy manually
let openai = OpenAI::new(auth, "https://api.openai.com/v1/")
.set_proxy("http://127.0.0.1:1080");
License
This library is distributed under the terms of the MIT license. See LICENSE for details.
관련 프로젝트 살펴보기
불러오는 중…