MCPcopy Create free account
hub / github.com/FuzzAnything/PromptFuzz / get_chat_response

Function get_chat_response

src/request/openai.rs:180–202  ·  view source on GitHub ↗

Get a response for a chat request

(
    request: CreateChatCompletionRequest,
)

Source from the content-addressed store, hash-verified

178
179/// Get a response for a chat request
180async fn get_chat_response(
181 request: CreateChatCompletionRequest,
182) -> Result<CreateChatCompletionResponse> {
183 let client: &Client<OpenAIConfig> = get_client().unwrap();
184 for _retry in 0..config::RETRY_N {
185 let response = client
186 .chat()
187 .create(request.clone())
188 .await
189 .map_err(eyre::Report::new);
190 match is_critical_err(&response) {
191 crate::Critical::Normal => {
192 let response = response?;
193 return Ok(response);
194 }
195 crate::Critical::NonCritical => {
196 continue;
197 }
198 crate::Critical::Critical => return Err(response.err().unwrap()),
199 }
200 }
201 Err(FuzzerError::RetryError(format!("{request:?}"), config::RETRY_N).into())
202}
203
204
205

Callers 1

generate_program_by_chatFunction · 0.85

Calls 2

get_clientFunction · 0.85
is_critical_errFunction · 0.85

Tested by

no test coverage detected