Missing space.
This commit is contained in:
parent
ac9a691103
commit
7a6a17a78b
|
@ -73,4 +73,18 @@ pub struct PendingDownload {
|
|||
// We're using the HuggingFace identifier as the model ID for now
|
||||
// We should consider using a different identifier in the future if more
|
||||
// models sources are added.
|
||||
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||
#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
|
||||
pub struct Model {
|
||||
pub id: ModelID,
|
||||
pub name: String,
|
||||
pub summary: String,
|
||||
pub size: String,
|
||||
pub requires: String,
|
||||
pub architecture: String,
|
||||
pub released_at: DateTime<Utc>,
|
||||
pub files: Vec<File>,
|
||||
pub author: Author,
|
||||
pub like_count: u32,
|
||||
pub download_count: u32,
|
||||
pub metrics: HashMap<String, f32>,
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
pub mod data;
|
||||
pub mod open_ai;
|
||||
pub mod protocol;
|
|
@ -0,0 +1,127 @@
|
|||
|
||||
use crate::data::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Message {
|
||||
pub content: String,
|
||||
pub role: Role,
|
||||
pub name: Option<String>,
|
||||
}
|
||||
|
||||
// Based on https://platform.openai.com/docs/api-reference/chat/object
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct ChatRequestData {
|
||||
pub messages: Vec<Message>,
|
||||
|
||||
// Not really necesary but it is part of the OpenAI API. We are going to send the id
|
||||
// of the model currently loaded.
|
||||
pub model: ModelID,
|
||||
|
||||
pub frequency_penalty: Option<f32>,
|
||||
pub logprobs: Option<bool>,
|
||||
pub top_logprobs: Option<u32>,
|
||||
pub max_tokens: Option<u32>,
|
||||
pub presence_penalty: Option<f32>,
|
||||
pub seed: Option<u32>,
|
||||
pub stop: Option<Vec<String>>,
|
||||
pub stream: Option<bool>,
|
||||
pub temperature: Option<f32>,
|
||||
pub top_p: Option<f32>,
|
||||
|
||||
// Adding the following fields since there are part of the OpenAI API,
|
||||
// but are not likely to be used in the first version of the client
|
||||
pub n: Option<u32>,
|
||||
pub logit_bias: Option<HashMap<String, f32>>,
|
||||
}
|
||||
|
||||
// Shared structs for ChatResponse and ChatResponseChunk
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct MessageData {
|
||||
pub content: String,
|
||||
pub role: Role,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
|
||||
pub enum Role {
|
||||
#[serde(rename = "system")]
|
||||
System,
|
||||
#[serde(rename = "user")]
|
||||
User,
|
||||
#[serde(rename = "assistant")]
|
||||
Assistant,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct TopLogProbsItemData {
|
||||
pub token: String,
|
||||
pub logprob: f32,
|
||||
pub bytes: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct LogProbsItemData {
|
||||
pub token: String,
|
||||
pub logprob: f32,
|
||||
pub bytes: Option<Vec<u8>>,
|
||||
pub top_logprobs: Vec<TopLogProbsItemData>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct LogProbsData {
|
||||
pub content: Vec<LogProbsItemData>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub enum StopReason {
|
||||
#[serde(rename = "stop")]
|
||||
Stop,
|
||||
#[serde(rename = "length")]
|
||||
Length,
|
||||
#[serde(rename = "content_filter")]
|
||||
ContentFilter,
|
||||
}
|
||||
|
||||
// ChatResponse structs
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct ChoiceData {
|
||||
pub finish_reason: StopReason,
|
||||
pub index: u32,
|
||||
pub message: MessageData,
|
||||
pub logprobs: Option<LogProbsData>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct UsageData {
|
||||
pub completion_tokens: u32,
|
||||
pub prompt_tokens: u32,
|
||||
pub total_tokens: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct ChatResponseData {
|
||||
pub id: String,
|
||||
pub choices: Vec<ChoiceData>,
|
||||
pub created: u32,
|
||||
pub model: ModelID,
|
||||
pub system_fingerprint: String,
|
||||
pub usage: UsageData,
|
||||
|
||||
#[serde(default = "response_object")]
|
||||
pub object: String,
|
||||
}
|
||||
|
||||
fn response_object() -> String {
|
||||
"chat.completion".to_string()
|
||||
}
|
||||
|
||||
// ChatResponseChunk structs
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct ChunkChoiceData {
|
||||
pub finish_reason: Option<StopReason>,
|
||||
pub index: u32,
|
||||
pub delta: MessageData,
|
Loading…
Reference in New Issue