Skip to content

Commit

Permalink
fix(ai-help): artificial error triggers properly in the chat phase (#452
Browse files Browse the repository at this point in the history
)

* added triggers for errors in ai help

* typo

* typo

* Update src/api/ai_help.rs

Co-authored-by: Florian Dieminger <me@fiji-flo.de>

* Update src/ai/help.rs

Co-authored-by: Florian Dieminger <me@fiji-flo.de>

* fix(ai-help): artificial error triggers properly work in the chat phase

---------

Co-authored-by: Florian Dieminger <me@fiji-flo.de>
  • Loading branch information
argl and fiji-flo authored Mar 21, 2024
1 parent 7572e5b commit deb9d54
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/api/ai_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,6 @@ pub async fn ai_help(

match prepare_res? {
Some(ai_help_req) => {
qa_check_for_error_trigger(&ai_help_req.req.messages)?;

let sources = ai_help_req.refs;
let created_at = match record_sources(
&diesel_pool,
Expand Down Expand Up @@ -447,10 +445,15 @@ pub async fn ai_help(
user.id,
help_ids,
)?;
let qa_error_triggered =
qa_check_for_error_trigger(&ai_help_req.req.messages).is_err();
let stream = client.chat().create_stream(ai_help_req.req).await.unwrap();
let refs = stream::once(async move {
let sse_data =
sse::Data::new_json(ai_help_meta).map_err(OpenAIError::JSONDeserialize);
let sse_data = if qa_error_triggered {
Err(OpenAIError::InvalidArgument("Artificial Error".to_owned()))
} else {
sse::Data::new_json(ai_help_meta).map_err(OpenAIError::JSONDeserialize)
};
match sse_data {
Ok(sse_data) => Ok(sse::Event::Data(sse_data)),
Err(err) => {
Expand Down

0 comments on commit deb9d54

Please sign in to comment.