Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: PR Checks

on:
pull_request:
types: [opened, synchronize, reopened]
pull_request_target:
types: [opened, synchronize, reopened]

jobs:
build:
name: Build Workspace
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
override: true

- name: Cache cargo registry
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-

- name: Build workspace
run: cargo build --workspace --verbose

- name: Check formatting
run: cargo fmt --all -- --check

# - name: Run clippy
# run: cargo clippy --workspace -- -D warnings
2 changes: 1 addition & 1 deletion async-openai/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ async fn map_stream_error(value: EventSourceError) -> OpenAIError {
"Unreachable because read_response returns err when status_code {status_code} is invalid"
))
}
_ => OpenAIError::StreamError(StreamError::ReqwestEventSource(value.into())),
_ => OpenAIError::StreamError(StreamError::ReqwestEventSource(value)),
}
}

Expand Down
7 changes: 1 addition & 6 deletions async-openai/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Errors originating from API calls, parsing responses, and reading-or-writing to the file system.
use std::string::FromUtf8Error;

use reqwest::{header::HeaderValue, Response};
use serde::{Deserialize, Serialize};

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -82,10 +80,7 @@ pub struct WrappedError {

pub(crate) fn map_deserialization_error(e: serde_json::Error, bytes: &[u8]) -> OpenAIError {
let json_content = String::from_utf8_lossy(bytes);
tracing::error!(
"failed deserialization of: {}",
json_content
);
tracing::error!("failed deserialization of: {}", json_content);

OpenAIError::JSONDeserialize(e, json_content.to_string())
}
7 changes: 5 additions & 2 deletions async-openai/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'c, C: Config> Files<'c, C> {
#[cfg(test)]
mod tests {
use crate::{
types::{CreateFileRequestArgs, FilePurpose, FileExpiresAfter, FileExpiresAfterAnchor},
types::{CreateFileRequestArgs, FileExpiresAfter, FileExpiresAfterAnchor, FilePurpose},
Client,
};

Expand All @@ -89,7 +89,10 @@ mod tests {
let request = CreateFileRequestArgs::default()
.file(test_file_path)
.purpose(FilePurpose::FineTune)
.expires_after(FileExpiresAfter{ anchor: FileExpiresAfterAnchor::CreatedAt, seconds: 3600 })
.expires_after(FileExpiresAfter {
anchor: FileExpiresAfterAnchor::CreatedAt,
seconds: 3600,
})
.build()
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion async-openai/src/types/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum FilePurpose {
pub enum FileExpiresAfterAnchor {
#[default]
#[serde(rename = "created_at")]
CreatedAt
CreatedAt,
}

#[derive(Debug, Default, Clone, PartialEq)]
Expand Down
11 changes: 6 additions & 5 deletions async-openai/src/types/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ use super::{
ChatCompletionRequestUserMessageContentPart, ChatCompletionToolChoiceOption, CreateFileRequest,
CreateImageEditRequest, CreateImageVariationRequest, CreateMessageRequestContent,
CreateSpeechResponse, CreateTranscriptionRequest, CreateTranslationRequest, DallE2ImageSize,
EmbeddingInput, FileInput, FilePurpose, FunctionName, Image, ImageInput, ImageModel,
ImageResponseFormat, ImageSize, ImageUrl, ImagesResponse, ModerationInput, Prompt, Role, Stop,
TimestampGranularity, FileExpiresAfterAnchor
EmbeddingInput, FileExpiresAfterAnchor, FileInput, FilePurpose, FunctionName, Image,
ImageInput, ImageModel, ImageResponseFormat, ImageSize, ImageUrl, ImagesResponse,
ModerationInput, Prompt, Role, Stop, TimestampGranularity,
};

/// for `impl_from!(T, Enum)`, implements
Expand Down Expand Up @@ -985,9 +985,10 @@ impl AsyncTryFrom<CreateFileRequest> for reqwest::multipart::Form {
let mut form = reqwest::multipart::Form::new()
.part("file", file_part)
.text("purpose", request.purpose.to_string());

if let Some(expires_after) = request.expires_after {
form = form.text("expires_after[anchor]", expires_after.anchor.to_string())
form = form
.text("expires_after[anchor]", expires_after.anchor.to_string())
.text("expires_after[seconds]", expires_after.seconds.to_string());
}
Ok(form)
Expand Down
1 change: 1 addition & 0 deletions examples/assistants-code-interpreter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
.create(CreateFileRequest {
file: "./input/CASTHPI.csv".into(),
purpose: FilePurpose::Assistants,
expires_after: None,
})
.await?;

Expand Down
2 changes: 2 additions & 0 deletions examples/assistants-file-search/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
.create(CreateFileRequest {
file: "./input/uber-10k.pdf".into(),
purpose: FilePurpose::Assistants,
expires_after: None,
})
.await?;

Expand Down Expand Up @@ -84,6 +85,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
.create(CreateFileRequest {
file: "./input/lyft-10k.pdf".into(),
purpose: FilePurpose::Assistants,
expires_after: None,
})
.await?;

Expand Down
5 changes: 4 additions & 1 deletion examples/responses/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use std::error::Error;

use async_openai::{
types::responses::{
AllowedTools, CreateResponseArgs, Input, InputItem, InputMessageArgs, McpArgs, RequireApproval, RequireApprovalPolicy, Role, TextConfig, ToolDefinition::{Mcp, WebSearchPreview}, Verbosity, WebSearchPreviewArgs
AllowedTools, CreateResponseArgs, Input, InputItem, InputMessageArgs, McpArgs,
RequireApproval, RequireApprovalPolicy, Role, TextConfig,
ToolDefinition::{Mcp, WebSearchPreview},
Verbosity, WebSearchPreviewArgs,
},
Client,
};
Expand Down
2 changes: 2 additions & 0 deletions examples/vector-store-retrieval/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
.create(CreateFileRequest {
file: "./input/uber-10k.pdf".into(),
purpose: FilePurpose::Assistants,
expires_after: None,
})
.await?;

Expand All @@ -29,6 +30,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
.create(CreateFileRequest {
file: "./input/lyft-10k.pdf".into(),
purpose: FilePurpose::Assistants,
expires_after: None,
})
.await?;

Expand Down
Loading