-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🤖 openai + textinput blocks / logic added (#1096)
* 🤖 openai + textinput blocks / logic added * lint fixes * made langchain call async * renamed method * summary agent refactor * black reformat
- Loading branch information
1 parent
8e721ad
commit 5fec6d7
Showing
5 changed files
with
133 additions
and
2 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
56 changes: 56 additions & 0 deletions
56
platform/reworkd_platform/schemas/workflow/blocks/summarization_webhook.py
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,56 @@ | ||
import requests | ||
from loguru import logger | ||
from reworkd_platform.web.api.agent.model_settings import create_model | ||
from reworkd_platform.schemas.user import UserBase | ||
from reworkd_platform.schemas.agent import ModelSettings | ||
from langchain import LLMChain, PromptTemplate | ||
from lanarky.responses import StreamingResponse | ||
|
||
from reworkd_platform.schemas.workflow.base import Block, BlockIOBase | ||
|
||
|
||
class SummaryWebhookInput(BlockIOBase): | ||
prompt: str | ||
|
||
|
||
class SummaryWebhookOutput(SummaryWebhookInput): | ||
result: str | ||
|
||
|
||
class SummaryWebhook(Block): | ||
type = "SummaryWebhook" | ||
description = "Extract key details from text using OpenAI" | ||
input: SummaryWebhookInput | ||
|
||
async def run(self) -> BlockIOBase: | ||
logger.info(f"Starting {self.type}") | ||
|
||
try: | ||
response = await summarize_and_extract(self.input.prompt) | ||
logger.info(f"RESPONSE {response}") | ||
except Exception as err: | ||
logger.error(f"Failed to extract text with OpenAI: {err}") | ||
raise | ||
|
||
return SummaryWebhookOutput(**self.input.dict(), result=response) | ||
|
||
|
||
async def summarize_and_extract(prompt: str) -> str: | ||
llm = create_model( | ||
ModelSettings(), | ||
UserBase(id="", name=None, email="[email protected]"), | ||
streaming=False, | ||
) | ||
template = """ | ||
You are a chatbot assistant that assists users in summarizing and extracting information from given text. | ||
Question: {prompt} | ||
Answer:""" | ||
|
||
chain = LLMChain( | ||
llm=llm, prompt=PromptTemplate(template=template, input_variables=["prompt"]) | ||
) | ||
|
||
result = await chain.arun(prompt) | ||
return result |
23 changes: 23 additions & 0 deletions
23
platform/reworkd_platform/schemas/workflow/blocks/text_input_webhook.py
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,23 @@ | ||
import requests | ||
from loguru import logger | ||
|
||
from reworkd_platform.schemas.workflow.base import Block, BlockIOBase | ||
|
||
|
||
class TextInputWebhookInput(BlockIOBase): | ||
text: str | ||
|
||
|
||
class TextInputWebhookOutput(BlockIOBase): | ||
result: str | ||
|
||
|
||
class TextInputWebhook(Block): | ||
type = "TextInputWebhook" | ||
description = "Enter Text to extract key details from" | ||
input: TextInputWebhookInput | ||
|
||
async def run(self) -> BlockIOBase: | ||
logger.info(f"Starting {self.type}") | ||
|
||
return TextInputWebhookOutput(result=self.input.text) |
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