-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from neatwork-ai/chat-app-4
Chat App 4
- Loading branch information
Showing
33 changed files
with
1,232 additions
and
721 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use anyhow::{anyhow, Result}; | ||
use js_sys::Function; | ||
|
||
use crate::openai::{ | ||
msg::{GptRole, OpenAIMsg}, | ||
params::{OpenAIModels, OpenAIParams}, | ||
request::chat_raw, | ||
}; | ||
|
||
pub async fn get_chat_title( | ||
msg: &str, | ||
request_callback: &Function, | ||
) -> Result<String> { | ||
let mut prompts = Vec::new(); | ||
|
||
prompts.push(OpenAIMsg { | ||
role: GptRole::System, | ||
content: String::from( | ||
" | ||
- Context: Briefly describe the key topics or themes of the chat. | ||
- Title Specifications: The title should be concise, and not exceed 6 words. It should reflect the tone of the chat (e.g., professional, casual, informative, provocative, etc.). | ||
- Output: Provide a title that encapsulates the main focus of the chat. | ||
", | ||
), | ||
}); | ||
|
||
let main_prompt = format!( | ||
" | ||
Your task is to create a title for the following prompt: | ||
\"\"\"{}\"\"\" | ||
The title of the prompt is:", | ||
msg | ||
); | ||
|
||
prompts.push(OpenAIMsg { | ||
role: GptRole::User, | ||
content: main_prompt, | ||
}); | ||
|
||
let prompts = prompts.iter().map(|x| x).collect::<Vec<&OpenAIMsg>>(); | ||
|
||
let ai_params = | ||
OpenAIParams::empty(OpenAIModels::Gpt35Turbo).max_tokens(15); | ||
|
||
let chat = | ||
chat_raw(request_callback, &ai_params, &prompts, &[], &[]).await?; | ||
|
||
let mut answer = chat | ||
.choices | ||
.first() | ||
.ok_or_else(|| anyhow!("LLM Respose seems to be empty :("))? | ||
.message | ||
.content | ||
.clone(); | ||
|
||
answer = clean_title(answer); | ||
|
||
Ok(answer) | ||
} | ||
|
||
fn clean_title(answer: String) -> String { | ||
answer.replace("\"", "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
///< internal API endpoint definitions. | ||
pub mod scaffold_project; | ||
pub mod stream_code; | ||
pub mod get_chat_title; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.