Compare commits

..

3 Commits

Author SHA1 Message Date
Slavi Pantaleev
f6700ed601 Switch back to upstream async-openai
Once async-openai v0.31.0 gets released as a final version,
we'll be able top pull it from crates.io.

This does not quite compile yet, because of https://github.com/64bit/async-openai/issues/465
2025-11-08 13:33:46 +02:00
Slavi Pantaleev
f03126a9e1 Upgrade Rust (1.89.0 -> 1.90.0) 2025-10-26 09:00:01 +02:00
Slavi Pantaleev
7d46b926c1 Update services 2025-10-26 08:30:42 +02:00
10 changed files with 52 additions and 45 deletions

8
Cargo.lock generated
View File

@@ -200,8 +200,8 @@ dependencies = [
[[package]]
name = "async-openai"
version = "0.28.1"
source = "git+https://github.com/etkecc/async-openai?branch=async-openai-v0.28.1-patched#856953c2d4485342df625fd0525363362075e8a8"
version = "0.31.0-alpha.2"
source = "git+https://github.com/64bit/async-openai?branch=main#08cae25ff0aa84552ccb32960e640cca139398fb"
dependencies = [
"async-openai-macros",
"backoff",
@@ -210,7 +210,7 @@ dependencies = [
"derive_builder 0.20.2",
"eventsource-stream",
"futures",
"rand 0.8.5",
"rand 0.9.2",
"reqwest 0.12.23",
"reqwest-eventsource 0.6.0",
"secrecy",
@@ -226,7 +226,7 @@ dependencies = [
[[package]]
name = "async-openai-macros"
version = "0.1.0"
source = "git+https://github.com/etkecc/async-openai?branch=async-openai-v0.28.1-patched#856953c2d4485342df625fd0525363362075e8a8"
source = "git+https://github.com/64bit/async-openai?branch=main#08cae25ff0aa84552ccb32960e640cca139398fb"
dependencies = [
"proc-macro2",
"quote",

View File

@@ -17,7 +17,7 @@ path = "src/lib.rs"
[dependencies]
anthropic = { git = "https://github.com/etkecc/anthropic-rs.git", branch = "fix-content-block-image" }
anyhow = "1.0.*"
async-openai = { git = "https://github.com/etkecc/async-openai", branch = "async-openai-v0.28.1-patched" }
async-openai = { git = "https://github.com/64bit/async-openai", branch = "main" }
base64 = "0.22.*"
chrono = { version = "0.4.*", default-features = false, features = ["std", "now"] }
# We'd rather not depend on this, but we cannot use the ruma-events EventContent macro without it.

View File

@@ -4,7 +4,7 @@
# #
#######################################
FROM docker.io/rust:1.89.0-slim-trixie AS build
FROM docker.io/rust:1.90.0-slim-trixie AS build
RUN apt-get update && apt-get install -y build-essential pkg-config libssl-dev libsqlite3-dev

View File

@@ -4,7 +4,7 @@
# #
#######################################
FROM docker.io/rust:1.89.0-slim-trixie AS build
FROM docker.io/rust:1.90.0-slim-trixie AS build
RUN apt-get update && apt-get install -y build-essential pkg-config libssl-dev libsqlite3-dev

View File

@@ -1,6 +1,6 @@
services:
postgres:
image: docker.io/postgres:17.6-alpine
image: docker.io/postgres:18.0-alpine
user: ${UID}:${GID}
restart: unless-stopped
environment:
@@ -8,12 +8,13 @@ services:
POSTGRES_PASSWORD: synapse-password
POSTGRES_DB: homeserver
POSTGRES_INITDB_ARGS: --lc-collate C --lc-ctype C --encoding UTF8
PGDATA: /data
volumes:
- ./postgres:/var/lib/postgresql/data
- ./postgres:/data
- /etc/passwd:/etc/passwd:ro
synapse:
image: ghcr.io/element-hq/synapse:v1.137.0
image: ghcr.io/element-hq/synapse:v1.140.0
user: "${UID}:${GID}"
restart: unless-stopped
entrypoint: python
@@ -26,7 +27,7 @@ services:
- ./synapse/media-store:/media-store
element-web:
image: ghcr.io/element-hq/element-web:v1.11.110
image: ghcr.io/element-hq/element-web:v1.12.2
user: "${UID}:${GID}"
restart: unless-stopped
environment:

View File

@@ -1,6 +1,6 @@
services:
ollama:
image: docker.io/ollama/ollama:0.11.10
image: docker.io/ollama/ollama:0.12.6
restart: unless-stopped
ports:
- "${SERVICE_OLLAMA_BIND_PORT_HTTP}:11434"

View File

@@ -58,10 +58,6 @@ impl ImageSource {
impl From<ImageSource> for async_openai::types::ImageInput {
fn from(value: ImageSource) -> Self {
async_openai::types::ImageInput::from_vec_u8(
value.filename,
value.bytes,
value.mime_type.to_string(),
)
async_openai::types::ImageInput::from_vec_u8(value.filename, value.bytes)
}
}

View File

@@ -104,16 +104,16 @@ fn default_speech_to_text_model_id() -> String {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TextToSpeechConfig {
#[serde(default = "default_text_to_speech_model_id")]
pub model_id: async_openai::types::SpeechModel,
pub model_id: async_openai::types::audio::SpeechModel,
#[serde(default = "default_text_to_speech_voice")]
pub voice: async_openai::types::Voice,
pub voice: async_openai::types::audio::Voice,
#[serde(default = "default_text_to_speech_speed")]
pub speed: f32,
#[serde(default = "default_text_to_speech_response_format")]
pub response_format: async_openai::types::SpeechResponseFormat,
pub response_format: async_openai::types::audio::SpeechResponseFormat,
}
impl Default for TextToSpeechConfig {
@@ -127,22 +127,22 @@ impl Default for TextToSpeechConfig {
}
}
fn default_text_to_speech_model_id() -> async_openai::types::SpeechModel {
async_openai::types::SpeechModel::Tts1Hd
fn default_text_to_speech_model_id() -> async_openai::types::audio::SpeechModel {
async_openai::types::audio::SpeechModel::Tts1Hd
}
fn default_text_to_speech_voice() -> async_openai::types::Voice {
async_openai::types::Voice::Onyx
fn default_text_to_speech_voice() -> async_openai::types::audio::Voice {
async_openai::types::audio::Voice::Onyx
}
fn default_text_to_speech_speed() -> f32 {
1.0
}
fn default_text_to_speech_response_format() -> async_openai::types::SpeechResponseFormat {
fn default_text_to_speech_response_format() -> async_openai::types::audio::SpeechResponseFormat {
// The API defaults to mp3, but we prefer Opus because it's smaller.
// Our clients should all have support for it.
async_openai::types::SpeechResponseFormat::Opus
async_openai::types::audio::SpeechResponseFormat::Opus
}
#[derive(Debug, Clone, Serialize, Deserialize)]

View File

@@ -5,8 +5,9 @@ use async_openai::{
config::OpenAIConfig,
types::{
ChatCompletionRequestMessage, CreateChatCompletionRequestArgs, CreateImageEditRequestArgs,
CreateImageRequestArgs, CreateSpeechRequestArgs, CreateTranscriptionRequestArgs,
CreateImageRequestArgs,
DallE2ImageSize, Image, ImageModel, ImageResponseFormat,
audio::{AudioInput, CreateSpeechRequestArgs, CreateTranscriptionRequestArgs},
},
};
@@ -209,11 +210,7 @@ impl ControllerTrait for Controller {
let request = CreateTranscriptionRequestArgs::default()
.model(&speech_to_text_config.model_id)
.file(async_openai::types::AudioInput::from_vec_u8(
filename,
media,
mime_type.to_string(),
))
.file(AudioInput::from_vec_u8(filename, media))
.language(language.clone())
.build()?;
@@ -223,7 +220,7 @@ impl ControllerTrait for Controller {
"Sending OpenAI speech-to-text API request"
);
let response = self.client.audio().transcribe(request).await?;
let response = self.client.audio().transcription().create(request).await?;
tracing::trace!(
?response,
@@ -275,6 +272,19 @@ impl ControllerTrait for Controller {
async_openai::types::ImageQuality::HD => {
Some(async_openai::types::ImageQuality::Standard)
}
// New quality levels - keep as-is or downgrade to Standard
async_openai::types::ImageQuality::High => {
Some(async_openai::types::ImageQuality::Standard)
}
async_openai::types::ImageQuality::Medium => {
Some(async_openai::types::ImageQuality::Medium)
}
async_openai::types::ImageQuality::Low => {
Some(async_openai::types::ImageQuality::Low)
}
async_openai::types::ImageQuality::Auto => {
Some(async_openai::types::ImageQuality::Auto)
}
},
None => None,
}
@@ -471,7 +481,7 @@ impl ControllerTrait for Controller {
let voice = if let Some(voice_string) = params.voice_override {
// This is a hacky way to construct a Voice enum from the string we have.
let voice: serde_json::Result<async_openai::types::Voice> =
let voice: serde_json::Result<async_openai::types::audio::Voice> =
serde_json::from_str(&format!("\"{}\"", voice_string));
match voice {
Ok(voice) => voice,
@@ -511,7 +521,7 @@ impl ControllerTrait for Controller {
"Sending OpenAI text-to-speech API request"
);
let result = self.client.audio().speech(request).await?;
let result = self.client.audio().speech().create(request).await?;
Ok(TextToSpeechResult {
bytes: result.bytes.into(),
@@ -570,15 +580,15 @@ impl ControllerTrait for Controller {
}
fn response_format_to_mime_type(
response_format: &async_openai::types::SpeechResponseFormat,
response_format: &async_openai::types::audio::SpeechResponseFormat,
) -> Option<mxlink::mime::Mime> {
let content_type = match response_format {
async_openai::types::SpeechResponseFormat::Mp3 => "audio/mp3".to_owned(),
async_openai::types::SpeechResponseFormat::Wav => "audio/wav".to_owned(),
async_openai::types::SpeechResponseFormat::Opus => "audio/ogg".to_owned(),
async_openai::types::SpeechResponseFormat::Aac => "audio/aac".to_owned(),
async_openai::types::SpeechResponseFormat::Flac => "audio/flac".to_owned(),
async_openai::types::SpeechResponseFormat::Pcm => "audio/L8".to_owned(),
async_openai::types::audio::SpeechResponseFormat::Mp3 => "audio/mp3".to_owned(),
async_openai::types::audio::SpeechResponseFormat::Wav => "audio/wav".to_owned(),
async_openai::types::audio::SpeechResponseFormat::Opus => "audio/ogg".to_owned(),
async_openai::types::audio::SpeechResponseFormat::Aac => "audio/aac".to_owned(),
async_openai::types::audio::SpeechResponseFormat::Flac => "audio/flac".to_owned(),
async_openai::types::audio::SpeechResponseFormat::Pcm => "audio/L8".to_owned(),
};
match content_type.parse() {

View File

@@ -161,11 +161,11 @@ impl TryInto<OpenAITextToSpeechConfig> for TextToSpeechConfig {
type Error = String;
fn try_into(self) -> Result<OpenAITextToSpeechConfig, Self::Error> {
let model_id = convert_string_to_enum::<async_openai::types::SpeechModel>(&self.model_id)?;
let model_id = convert_string_to_enum::<async_openai::types::audio::SpeechModel>(&self.model_id)?;
let voice = convert_string_to_enum::<async_openai::types::Voice>(&self.voice)?;
let voice = convert_string_to_enum::<async_openai::types::audio::Voice>(&self.voice)?;
let response_format = convert_string_to_enum::<async_openai::types::SpeechResponseFormat>(
let response_format = convert_string_to_enum::<async_openai::types::audio::SpeechResponseFormat>(
&self.response_format,
)?;