-
Notifications
You must be signed in to change notification settings - Fork 28
Fix(ChattyLLM): Fix title generation to work with languages other than english #451
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -880,28 +880,22 @@ public function generateTitle(int $sessionId): JSONResponse { | |
| ) ?: Application::CHAT_USER_INSTRUCTIONS_TITLE; | ||
| $userInstructions = str_replace('{user}', $user->getDisplayName(), $userInstructions); | ||
|
|
||
| $systemPrompt = ''; | ||
| $firstMessage = $this->messageMapper->getFirstNMessages($sessionId, 1); | ||
| if ($firstMessage->getRole() === 'system') { | ||
| $systemPrompt = $firstMessage->getContent(); | ||
| } | ||
|
|
||
| $history = $this->getRawLastMessages($sessionId); | ||
| // history is a list of JSON strings | ||
| $history = array_map(static function (Message $message) { | ||
| return json_encode([ | ||
| 'role' => $message->getRole(), | ||
| 'content' => $message->getContent(), | ||
| ]); | ||
| ], JSON_THROW_ON_ERROR); | ||
| }, $history); | ||
|
|
||
| try { | ||
| $taskId = $this->scheduleLLMChatTask($userInstructions, $systemPrompt, $history, $sessionId, false); | ||
| $taskId = $this->scheduleLLMChatTask($userInstructions, $userInstructions, $history, $sessionId, false); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate prompt for moar accuracy.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hehe but why remove system prompt. That's meant for universal guidelines for the LLMs and probably should be taken into account here as well.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe the two prompts are competing for the llm's attention and IMHO the general assistant guidelines are not really needed for title generation.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with Marcel here. The "chat" system prompt won't help much on generating a title.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah yeah I see that now. Maybe the language guidelines should only be in the system prompt, the user instructions could be about only outputing the title and the examples (which are noice). but it's alright for the title generation I suppose if it's not user-influenced. |
||
| } catch (\Exception $e) { | ||
| return new JSONResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST); | ||
| } | ||
| return new JSONResponse(['taskId' => $taskId]); | ||
| } catch (\OCP\DB\Exception $e) { | ||
| } catch (\OCP\DB\Exception|\JsonException $e) { | ||
| $this->logger->warning('Failed to generate a title for the chat session', ['exception' => $e]); | ||
| return new JSONResponse(['error' => $this->l10n->t('Failed to generate a title for the chat session')], Http::STATUS_INTERNAL_SERVER_ERROR); | ||
marcelklehr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throw JSON errors