From 9449ef0a1e2e062539b40c3f11fa95f249ae1091 Mon Sep 17 00:00:00 2001 From: zhanglei Date: Thu, 4 Jul 2024 17:03:16 +0800 Subject: [PATCH] fmt --- src/langchain_lab/core/audio.py | 5 +---- src/langchain_lab/core/embedding.py | 1 - src/langchain_lab/core/llm.py | 1 - src/langchain_lab/scenarios/agents/__init__.py | 4 ++++ .../scenarios/agents/langgraph_agent/__init__.py | 0 .../agents/langgraph_agent/langgraph_demo_agent.py | 10 ++++++++++ 6 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 src/langchain_lab/scenarios/agents/langgraph_agent/__init__.py create mode 100644 src/langchain_lab/scenarios/agents/langgraph_agent/langgraph_demo_agent.py diff --git a/src/langchain_lab/core/audio.py b/src/langchain_lab/core/audio.py index ea17df3..12988c0 100644 --- a/src/langchain_lab/core/audio.py +++ b/src/langchain_lab/core/audio.py @@ -6,8 +6,5 @@ def openai_speech_to_text(audio_file_path): client = OpenAI(base_url=os.environ["OPENAI_API_BASE"], api_key=os.environ["OPENAI_API_KEY"]) audio_file = open(audio_file_path, "rb") - transcription = client.audio.transcriptions.create( - model="whisper-1", - file=audio_file - ) + transcription = client.audio.transcriptions.create(model="whisper-1", file=audio_file) print(transcription.text) diff --git a/src/langchain_lab/core/embedding.py b/src/langchain_lab/core/embedding.py index 02d52e9..ca62958 100644 --- a/src/langchain_lab/core/embedding.py +++ b/src/langchain_lab/core/embedding.py @@ -21,7 +21,6 @@ from langchain_community.embeddings import HuggingFaceEmbeddings, OpenAIEmbeddings from langchain_community.vectorstores import FAISS - from langchain_lab import logger diff --git a/src/langchain_lab/core/llm.py b/src/langchain_lab/core/llm.py index 91f4a42..a8fad45 100644 --- a/src/langchain_lab/core/llm.py +++ b/src/langchain_lab/core/llm.py @@ -21,7 +21,6 @@ from langchain.chat_models.base import BaseChatModel from langchain.schema import LLMResult from langchain_openai import ChatOpenAI - from openai import OpenAI from langchain_lab import logger diff --git a/src/langchain_lab/scenarios/agents/__init__.py b/src/langchain_lab/scenarios/agents/__init__.py index 32664c3..71d3baa 100644 --- a/src/langchain_lab/scenarios/agents/__init__.py +++ b/src/langchain_lab/scenarios/agents/__init__.py @@ -1,4 +1,7 @@ from langchain_lab.core.agents import agent_register +from langchain_lab.scenarios.agents.langgraph_agent.langgraph_demo_agent import ( + LangGraphDemoAgent, +) from langchain_lab.scenarios.agents.translation_agent.translation_english2chinese import ( TranslationEnglish2Chinese, ) @@ -8,3 +11,4 @@ agent_register(WikipediaAgent()) agent_register(TranslationEnglish2Chinese()) +agent_register(LangGraphDemoAgent()) diff --git a/src/langchain_lab/scenarios/agents/langgraph_agent/__init__.py b/src/langchain_lab/scenarios/agents/langgraph_agent/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/langchain_lab/scenarios/agents/langgraph_agent/langgraph_demo_agent.py b/src/langchain_lab/scenarios/agents/langgraph_agent/langgraph_demo_agent.py new file mode 100644 index 0000000..fe07e26 --- /dev/null +++ b/src/langchain_lab/scenarios/agents/langgraph_agent/langgraph_demo_agent.py @@ -0,0 +1,10 @@ +from typing import Any, Dict + +from langchain_lab.core.agents import LabAgent + + +class LangGraphDemoAgent(LabAgent): + description = "这是一个演示 LangGraph 的 Agent" + + def agent_invoke(self, inputs: Dict[str, Any]) -> Dict[str, Any]: + return {"input": inputs, "output": "hello world"}