1
1
use openai_api_rs:: v1:: chat_completion:: {
2
- ChatCompletionMessage , ChatCompletionRequest , Function , FunctionParameters , JSONSchemaDefine ,
3
- JSONSchemaType , GPT3_5_TURBO ,
2
+ ChatCompletionMessage , ChatCompletionRequest , Function as F , FunctionParameters ,
3
+ JSONSchemaDefine , JSONSchemaType , GPT3_5_TURBO ,
4
4
} ;
5
5
use std:: collections:: HashMap ;
6
6
7
- use crate :: constants:: { FINAL_EXPLANATION_TEMPERATURE , FUNCTIONS_CALLS_TEMPERATURE } ;
7
+ use crate :: { constants:: CHAT_COMPLETION_TEMPERATURE , utils :: functions :: Function } ;
8
8
9
9
pub fn generate_completion_request (
10
10
messages : Vec < ChatCompletionMessage > ,
11
- with_functions : bool ,
11
+ function_call : & str ,
12
12
) -> ChatCompletionRequest {
13
- //All the chat completion requests will have functions except for the final explanation request
14
- if with_functions {
15
- ChatCompletionRequest {
16
- model : GPT3_5_TURBO . into ( ) ,
17
- messages,
18
- functions : Some ( functions ( ) ) ,
19
- function_call : None ,
20
- temperature : Some ( FUNCTIONS_CALLS_TEMPERATURE ) ,
21
- top_p : None ,
22
- n : None ,
23
- stream : None ,
24
- stop : None ,
25
- max_tokens : None ,
26
- presence_penalty : None ,
27
- frequency_penalty : None ,
28
- logit_bias : None ,
29
- user : None ,
30
- }
31
- } else {
32
- ChatCompletionRequest {
33
- model : GPT3_5_TURBO . into ( ) ,
34
- messages,
35
- functions : None ,
36
- function_call : None ,
37
- temperature : Some ( FINAL_EXPLANATION_TEMPERATURE ) ,
38
- top_p : None ,
39
- n : None ,
40
- stream : None ,
41
- stop : None ,
42
- max_tokens : None ,
43
- presence_penalty : None ,
44
- frequency_penalty : None ,
45
- logit_bias : None ,
46
- user : None ,
47
- }
13
+ // https://platform.openai.com/docs/api-reference/chat/create
14
+ ChatCompletionRequest {
15
+ model : GPT3_5_TURBO . into ( ) ,
16
+ messages,
17
+ functions : Some ( functions ( ) ) ,
18
+ function_call : Some ( function_call. into ( ) ) ,
19
+ temperature : Some ( CHAT_COMPLETION_TEMPERATURE ) ,
20
+ top_p : None ,
21
+ n : None ,
22
+ stream : None ,
23
+ stop : None ,
24
+ max_tokens : None ,
25
+ presence_penalty : None ,
26
+ frequency_penalty : None ,
27
+ logit_bias : None ,
28
+ user : None ,
48
29
}
49
30
}
50
31
51
- pub fn functions ( ) -> Vec < Function > {
32
+ // https://platform.openai.com/docs/api-reference/chat/create#chat/create-functions
33
+ pub fn functions ( ) -> Vec < F > {
52
34
vec ! [
53
- Function {
54
- name: "none" . into ( ) ,
35
+ F {
36
+ name: Function :: Done . to_string ( ) ,
55
37
description: Some ( "This is the final step, and signals that you have enough information to respond to the user's query." . into( ) ) ,
56
38
parameters: Some ( FunctionParameters {
57
39
schema_type: JSONSchemaType :: Object ,
58
40
properties: Some ( HashMap :: new( ) ) ,
59
41
required: None ,
60
42
} ) ,
61
43
} ,
62
- Function {
63
- name: "search_codebase" . into ( ) ,
44
+ F {
45
+ name: Function :: SearchCodebase . to_string ( ) ,
64
46
description: Some ( "Search the contents of files in a repository semantically. Results will not necessarily match search terms exactly, but should be related." . into( ) ) ,
65
47
parameters: Some ( FunctionParameters {
66
48
schema_type: JSONSchemaType :: Object ,
@@ -77,8 +59,8 @@ pub fn functions() -> Vec<Function> {
77
59
required: Some ( vec![ "query" . into( ) ] ) ,
78
60
} )
79
61
} ,
80
- Function {
81
- name: "search_path" . into ( ) ,
62
+ F {
63
+ name: Function :: SearchPath . to_string ( ) ,
82
64
description: Some ( "Search the pathnames in a repository. Results may not be exact matches, but will be similar by some edit-distance. Use when you want to find a specific file" . into( ) ) ,
83
65
parameters: Some ( FunctionParameters {
84
66
schema_type: JSONSchemaType :: Object ,
@@ -95,8 +77,8 @@ pub fn functions() -> Vec<Function> {
95
77
required: Some ( vec![ "path" . into( ) ] ) ,
96
78
} )
97
79
} ,
98
- Function {
99
- name: "search_file" . into ( ) ,
80
+ F {
81
+ name: Function :: SearchFile . to_string ( ) ,
100
82
description: Some ( "Search a file returned from functions.search_path. Results will not necessarily match search terms exactly, but should be related." . into( ) ) ,
101
83
parameters: Some ( FunctionParameters {
102
84
schema_type: JSONSchemaType :: Object ,
@@ -130,13 +112,13 @@ pub fn system_message() -> String {
130
112
Follow these rules at all times:
131
113
- Respond with functions to find information related to the query, until all relevant information has been found.
132
114
- If the output of a function is not relevant or sufficient, try the same function again with different arguments or try using a different function
133
- - When you have enough information to answer the user's query respond with functions.none
115
+ - When you have enough information to answer the user's query respond with functions.done
134
116
- Do not assume the structure of the codebase, or the existence of files or folders
135
117
- Never respond with a function that you've used before with the same arguments
136
118
- Do NOT respond with functions.search_file unless you have already called functions.search_path
137
- - If after making a path search the query can be answered by the existance of the paths, use the functions.none function
119
+ - If after making a path search the query can be answered by the existance of the paths, use the functions.done function
138
120
- Only refer to paths that are returned by the functions.search_path function when calling functions.search_file
139
- - If after attempting to gather information you are still unsure how to answer the query, respond with the functions.none function
121
+ - If after attempting to gather information you are still unsure how to answer the query, respond with the functions.done function
140
122
- Always respond with a function call. Do NOT answer the question directly"# ,
141
123
)
142
124
}
0 commit comments