Add function calling support using bolt-fc-1b (#35)

This commit is contained in:
Adil Hafeez 2024-09-10 14:24:46 -07:00 committed by GitHub
parent fdfad87347
commit 7b5203a2ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
39 changed files with 1763 additions and 416 deletions

View file

@ -53,37 +53,75 @@ pub struct SearchPointsResponse {
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NERRequest {
pub input: String,
pub labels: Vec<String>,
pub model: String,
pub struct ToolParameter {
#[serde(rename = "type")]
#[serde(skip_serializing_if = "Option::is_none")]
pub parameter_type: Option<String>,
pub description: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub required: Option<bool>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Entity {
pub text: String,
pub label: String,
pub score: f64,
pub struct ToolParameters {
#[serde(rename = "type")]
pub parameters_type: String,
pub properties: HashMap<String, ToolParameter>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NERResponse {
pub data: Vec<Entity>,
pub struct ToolsDefinition {
pub name: String,
pub description: String,
pub parameters: ToolParameters,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BoltFCResponse {
pub model: String,
pub message: open_ai::Message,
pub done_reason: String,
pub done: bool,
pub resolver_name: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum IntOrString {
Integer(i32),
Text(String),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ToolCallDetail {
pub name: String,
pub arguments: HashMap<String, IntOrString>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BoltFCToolsCall {
pub tool_calls: Vec<ToolCallDetail>,
}
pub mod open_ai {
use serde::{Deserialize, Serialize};
use super::ToolsDefinition;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ChatCompletions {
#[serde(default)]
pub model: String,
pub messages: Vec<Message>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tools: Option<Vec<ToolsDefinition>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Message {
pub role: String,
pub content: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub model: Option<String>,
}
}

View file

@ -80,19 +80,28 @@ pub struct Endpoint {
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Entity {
pub struct Parameter {
pub name: String,
#[serde(rename = "type")]
pub parameter_type: Option<String>,
pub description: String,
pub required: Option<bool>,
pub description: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum PromptType {
#[serde(rename = "function_resolver")]
FunctionResolver,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PromptTarget {
#[serde(rename = "type")]
pub prompt_type: String,
pub prompt_type: PromptType,
pub name: String,
pub description: Option<String>,
pub few_shot_examples: Vec<String>,
pub entities: Option<Vec<Entity>>,
pub parameters: Option<Vec<Parameter>>,
pub endpoint: Option<Endpoint>,
pub system_prompt: Option<String>,
}
@ -119,27 +128,29 @@ system_prompt: |
- Use miles per hour for wind speed
prompt_targets:
- type: context_resolver
- type: function_resolver
name: weather_forecast
few_shot_examples:
- what is the weather in New York?
endpoint:
cluster: weatherhost
path: /weather
entities:
parameters:
- name: location
required: true
description: "The location for which the weather is requested"
- type: context_resolver
- type: function_resolver
name: weather_forecast_2
few_shot_examples:
- what is the weather in New York?
endpoint:
cluster: weatherhost
path: /weather
entities:
parameters:
- name: city
description: "The location for which the weather is requested"
ratelimits:
- provider: open-ai-gpt-4