Comments (3)
yes, I met the same issue as you. Even if not using with_structured_output, the with_config cannot propogate the paramters.
from langchain.
yes, I met the same issue as you. Even if not using with_structured_output, the with_config cannot propogate the paramters.
Do you have an alternative implementation you use?
from langchain.
A workaround if anyone encounters the same issue
from langchain_core.pydantic_v1 import BaseModel, Field
from langchain_openai import ChatOpenAI
from langchain_openai.chat_models.base import convert_to_openai_tool
from langchain_core.runnables import ConfigurableField
from typing import Dict, Any, Optional
from langchain_core.output_parsers.openai_tools import PydanticToolsParser
class Joke(BaseModel):
setup: str = Field(description="The setup of the joke")
punchline: str = Field(description="The punchline to the joke")
class ChatOpenAIWithStructedOutput(ChatOpenAI):
output_structure: Optional[Dict[str, Any] ] = None
@property
def _default_params(self) -> Dict[str, Any]:
"""Get the default parameters for calling OpenAI API."""
params = {
"model": self.model_name,
"stream": self.streaming,
"n": self.n,
"temperature": self.temperature,
**self.model_kwargs,
}
if self.output_structure is not None:
tools = [self.output_structure]
tool_choice = {"type" : "function", "function" : {"name" : tools[0]["function"]["name"]}}
params["tools"] = tools
params["tool_choice"] = tool_choice
if self.max_tokens is not None:
params["max_tokens"] = self.max_tokens
return params
model = ChatOpenAIWithStructedOutput(model="gpt-3.5-turbo-0125", temperature=2, api_key="API_KEY").configurable_fields(
temperature=ConfigurableField(id="temperature", name="Temperature", description="The temperature of the model"),
output_structure=ConfigurableField(id="output_structure", name="output_structure", description="The output schema of the model"))
structured_llm = model.with_config(configurable={"output_structure" : convert_to_openai_tool(Joke)}) | PydanticToolsParser(tools=[Joke], first_tool_only=True)
structured_llm.with_config(configurable={"temperature" : 1}).invoke("Tell me a joke about cats")
from langchain.
Related Issues (20)
- [OutputFixingParser] I am using the OutputFixingParser component according to the official documentation, but an exception has occurred
- Issue: Document loader for Notion DB doesn't supports KeyError: 'name'
- [Google Generative AI] Structured Output doesn't work with advanced schema
- Langchain RetrievalQAWithSourcesChain throwing ValueError: Missing some input keys: {'context'} HOT 3
- IME Input Handling Issue in LangChain Chat Playground
- IME Input Handling Issue in Chat LangChain HOT 2
- OllamaFunction returns Object of type ModelMetaclass is not JSON serializable following example on documentation
- how to insert id_prefix when upserting using langchain pinecone.from_documents??? or what is the alternative? because id_prefix is very important when we want to delete specific vectors
- how to insert id_prefix when upserting using langchain pinecone.from_documents??? or what is the alternative? because id_prefix is very important when we want to delete specific vectors #24235
- DOC: <Please wri知识库交叉融合,在项目使用中,我有一些公用知识库和私有知识库,我想在回答的时候将私有知识库和公用的知识库结合起来,这怎么实现?后期可以更新吗te a comprehensive title after the 'DOC: ' prefix>
- LangChain AzureOpenAIEmbeddings is not working due to model trying to access microsoft
- No module named 'langchain.transformers' HOT 3
- issue using tools with ollama local models
- variable chat_history should be a list of base messages, got
- Missing key error - Using PromptTemplate and GraphCypherQAChain. HOT 6
- AzureSearch vector store does not support access token authentication. FIX Suggested
- TavilySearch parameters don't change the output. HOT 1
- An output parsing error occurred.
- raise ValueError( ValueError: OpenAIChat currently only supports single prompt, got
- ConnectError: [Errno -3] Temporary failure in name resolution
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from langchain.