-
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 #42 from nextcloud/feat/add-new-providers
Feat: add new providers
- Loading branch information
Showing
4 changed files
with
94 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
"""A chain that changes the tone of a text | ||
""" | ||
|
||
from typing import Any | ||
|
||
from langchain.prompts import PromptTemplate | ||
from langchain.schema.prompt_template import BasePromptTemplate | ||
from langchain_core.runnables import Runnable | ||
|
||
class ChangeToneProcessor(): | ||
|
||
runnable: Runnable | ||
|
||
""" | ||
A topics chain | ||
""" | ||
system_prompt: str = "You're an AI assistant tasked with rewriting the text given to you by the user in another tone." | ||
user_prompt: BasePromptTemplate = PromptTemplate( | ||
input_variables=["text", "tone"], | ||
template="""Reformulate the following text in a " {tone} " tone in its original language without mentioning the language. Output only the reformulation, nothing else, no introductory sentence. Here is the text: | ||
" | ||
{text} | ||
" | ||
Output only the reformulated text, nothing else. Do not add an introductory sentence. | ||
""" | ||
) | ||
|
||
def __init__(self, runnable: Runnable): | ||
self.runnable = runnable | ||
|
||
|
||
def __call__(self, inputs: dict[str,Any], | ||
) -> dict[str, Any]: | ||
output = self.runnable.invoke({"user_prompt": self.user_prompt.format_prompt(text=inputs['input'], tone=inputs['tone']), "system_prompt": self.system_prompt}) | ||
return {'output': output} |
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,40 @@ | ||
# SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
"""A chain to proofread a text | ||
""" | ||
|
||
from typing import Any | ||
from langchain.prompts import PromptTemplate | ||
from langchain.schema.prompt_template import BasePromptTemplate | ||
from langchain_core.runnables import Runnable | ||
|
||
|
||
class ProofreadProcessor: | ||
""" | ||
A proofreading chain | ||
""" | ||
system_prompt: str = "You're an AI assistant tasked with proofreading the text given to you by the user." | ||
user_prompt: BasePromptTemplate = PromptTemplate( | ||
input_variables=["text"], | ||
template=""" | ||
Detect all grammar and spelling mistakes of the following text in its original language. Output only the list of mistakes in bullet points. | ||
" | ||
{text} | ||
" | ||
Give me the list of all mistakes in the above text in its original language. Do not output the language. Output only the list in bullet points, nothing else, no introductory or explanatory text. | ||
""" | ||
) | ||
|
||
runnable: Runnable | ||
|
||
def __init__(self, runnable: Runnable): | ||
self.runnable = runnable | ||
|
||
def __call__( | ||
self, | ||
inputs: dict[str, Any], | ||
) -> dict[str, Any]: | ||
output = self.runnable.invoke({"user_prompt": self.user_prompt.format_prompt(text=inputs['input']), "system_prompt": self.system_prompt}) | ||
return {'output': output} |
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