-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add function calling support using bolt-fc-1b #35
Conversation
function_resolver/app/template.py
Outdated
elements += self.handler._format_system(tools) | ||
|
||
if message.role == "user": | ||
elements += self.handler._format_user(content=message.content) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use dict or a better way to handle this
function_resolver/requirements.txt
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add specific version
function_resolver/test/test.sh
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should organize using makefile in the future
function_resolver/app/template.py
Outdated
Converts elements to token ids. | ||
""" | ||
token_ids = [] | ||
for elem in elements: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this loop would be slow, any chance we can vectorize this?
@adilhafeez Thanks for making this PR! Here are some changes I think you need to make:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments -- I did not read the non rust code. Let me know if you'd like me to.
Looks like lints and tests are failing
pub score: f64, | ||
pub struct ToolParameters { | ||
#[serde(rename = "type")] | ||
pub parameters_type: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not enum? also why not simply name it type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be enum, will update
pub parameter_type: Option<String>, | ||
pub description: String, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub required: Option<bool>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to say that required
parameter is optional to enable following use case. In this spec, when required is missing then parameter is optional. For example city is required and days, units are optional parameters.
parameters:
- name: city
required: true
description: The city for which the weather forecast is requested.
- name: days
description: The number of days for which the weather forecast is requested.
- name: units
description: The units in which the weather forecast is requested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting API choice, instead of using required: false
public-types/src/common_types.rs
Outdated
pub model: String, | ||
pub created_at: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not chrono::DateTime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated to use chrono::DateTime
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
#[serde(untagged)] | ||
pub enum IntOrString { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it is more descriptive to name the int and the string by names that tell us why someone would use a string or an int in this field.
} | ||
|
||
pub mod open_ai { | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::ToolsDefinition; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct ChatCompletions { | ||
#[serde(default)] | ||
pub model: String, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between the model here and in the message?
envoyfilter/src/stream_context.rs
Outdated
debug!("function_resolver response str: {:?}", body_str); | ||
|
||
let mut resp = serde_json::from_str::<FunctionCallingModelResponse>(&body_str).unwrap(); | ||
resp.resolver_name = Some(callout_context.prompt_target.as_ref().unwrap().name.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A lot of unwrap re-introduction all over the place in this PR. Is this the best error handling we can do?
info!("possibly some required parameters are missing, send back the response"); | ||
let resp_str = serde_json::to_string(&resp).unwrap(); | ||
self.send_http_response( | ||
StatusCode::OK.as_u16().into(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So why would this be 200, if the response was invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part needs to be rewritten - will update this code block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rewrote this part, its better now
envoyfilter/src/stream_context.rs
Outdated
return; | ||
} | ||
}; | ||
let tool_call_details = _tool_call_details.unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of this block of code seems to be like this due to all the print line debugging, did you mean to clean this up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleaned it up
// add original user prompt | ||
messages.push({ | ||
Message { | ||
role: USER_ROLE.to_string(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should role and model be enums?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want to restrict role and model to be limited to fixed values. New models keep coming in. And to support new model it would require change in spec.
For Role I am still thinking wether we should use enum or not. I am leaning toward using enum and list all possible roles in spec that are used by API based LLMs that we support in open-message-format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With all the inline requests to local servers I have been thinking that this code would benefit from some sort of strongly typed state machine pattern inspired by a common rust pattern, examples:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@junr03 I've been thinking about it too. The orchestration inside filter can be viewed and programmed as state machine. And if done right, it can become much easier to visualize and reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of the comments are outstanding. Nothing is truly a blocker, so I'll approve because I know you want to land this. But I believe addressing the comments will improve quality and readability.
Also -- lint and test are still not passing. |
This code change adds bolt-fc-1b to bolt gateway. There are several changes that went in to support bolt-fc-1b. Here is a summary of key changes.
config-generator
, its task is to take envoy.template.yaml, katanemo-config and generate final envoy.yaml that can be used by envoy to bootstrap