Skip to content
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

Initial Draft #1

Merged
merged 16 commits into from
Jun 24, 2024
Merged

Initial Draft #1

merged 16 commits into from
Jun 24, 2024

Conversation

ivanleomk
Copy link
Collaborator

I've created a procedural macro that implements a get_info() method. This get_info() method will in turn generate a json obj that will take the individual types + names + comments.

Eg.

#[derive(InstructMacro, Deserialize, Serialize, Debug)]
/// This is a model which represents a single individual user
struct UserInfo {
    /// This is the name of the user
    name: String,
    /// This is the age of the user
    age: u8,
    /// This is the city of the user
    city: String,
}

This gets transformed into

StructInfo {
  name: "UserInfo",
  description: "This is a model which represents a single individual user",
  parameters: [
    ParameterInfo {
      name: "name",
      type: "String",
      comment: "This is the name of the user"
    },
    ParameterInfo {
      name: "age",
      type: "u8",
      comment: "This is the age of the user"
    },
    ParameterInfo {
      name: "city",
      type: "String",
      comment: "This is the city of the user"
    }
  ]
}

We then take this and use it to generate a function definition which can be called. Since it's a simple struct, we can just deserialize it once we get the response back from OpenAI

@ivanleomk
Copy link
Collaborator Author

I put an example of what an API might look like in main.rs which will show how to do structured extraction to get a UserInfo object

let parsed_model: StructInfo = T::get_info();
let mut error_message: Option<String> = None;

for _ in 0..3 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use max_retries

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the things I'm struggling with in rust is that I couldn't find a way to extend the object (eg.

impl InstructorClientReq extends ChatCompletionReq{
maxRetries: u8,
...req
}

This doesn't quite seem to exist and the articles I've seen recommend simply doing something like

impl InstructorClientReq{
maxRetries: u8,
req: ChatCompletionReq
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

impl InstructorClientReq{
maxRetries: u8,
req: ChatCompletionReq
}

looks right.
make sure to also specify mode as tools since in'll be different for llama-cpp server

@jxnl
Copy link
Contributor

jxnl commented Jun 22, 2024

typos in the read me
how do imports work in rust?

@jxnl
Copy link
Contributor

jxnl commented Jun 22, 2024

and we make a todo list of common types

int
str
float
bool

List[Object]
Literal[a,b,c]

@ivanleomk
Copy link
Collaborator Author

and we make a todo list of common types

int str float bool

List[Object] Literal[a,b,c]

Yup I think we should just define a simple mapping of eg. u8,u16.u32, i8 -> Number and we can update this

@ivanleomk
Copy link
Collaborator Author

typos in the read me how do imports work in rust?

Depends on how we're using it. If you're using a mod from another file, you need to use the mod <filename> syntax but if it';s another crate than you use crate_name::<import_path> i believe

instruct-macros/Cargo.toml Outdated Show resolved Hide resolved
instructor/Cargo.toml Outdated Show resolved Hide resolved
@ivanleomk ivanleomk merged commit a79c30a into main Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants