Skip to content
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

Getting from runnables.dict() in RunnableSequence not all expected variables. #19255

Closed
5 tasks done
SimonStanley1 opened this issue Mar 19, 2024 · 3 comments · Fixed by #19258
Closed
5 tasks done

Getting from runnables.dict() in RunnableSequence not all expected variables. #19255

SimonStanley1 opened this issue Mar 19, 2024 · 3 comments · Fixed by #19258
Labels
🤖:improvement Medium size change to existing code to handle new use-cases 🔌: openai Primarily related to OpenAI integrations Ɑ: Runnables Related to Runnables

Comments

@SimonStanley1
Copy link

SimonStanley1 commented Mar 19, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

from langchain_openai import AzureChatOpenAI
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import RunnableLambda, RunnableSequence
from langchain_core.messages import HumanMessage

def langchain_model(prompt_func: callable) -> RunnableSequence:

    model = AzureChatOpenAI(azure_deployment="gpt-35-16k", temperature=0)
    return RunnableLambda(prompt_func) | model | StrOutputParser()

def prompt_func(
    _dict: dict,
) -> list:

    question = _dict.get("question")
    texts = _dict.get("texts")

    text_message = {
        "type": "text",
        "text": (
            "You are a classification system for Procurement Documents. Answer the question solely on the provided Reference texts.\n"
            "If you cant find a answer reply exactly like this: 'Sorry i dont have an answer for youre question'\n"
            "Return the answer as a string in the language the question is written in.\n\n "
            f"User-provided question: \n"
            f"{question} \n\n"
            "Reference texts:\n"
            f"{texts}"
        ),
    }

    return [HumanMessage(content=[text_message])]

model = langchain_model(prompt_func=prompt_func)

for steps, runnable in model:
    try:
        print(runnable[0].dict())
    except:
        print(runnable)

Error Message and Stack Trace (if applicable)

for AzureChatOpenAI as a component you will just get this output as dict:

{'model': 'gpt-3.5-turbo', 'stream': False, 'n': 1, 'temperature': 0.0, '_type': 'azure-openai-chat'}.

Description

This is not enough if you want to log the model with MLFlow, the deployment_name is definitely needed and needs to be gotten from dict. See related issue: mlflow/mlflow#11439. Expected output would have more details at least a deployment name.

System Info

System Information

OS: Darwin
Python Version: 3.10.11 (v3.10.11:7d4cc5aa85, Apr 4 2023, 19:05:19) [Clang 13.0.0]

Package Information

langchain_core: 0.1.32
langchain: 0.1.12
langchain_community: 0.0.28
langsmith: 0.1.26
langchain_openai: 0.0.8
langchain_text_splitters: 0.0.1

Packages not installed (Not Necessarily a Problem)

The following packages were not found:

langgraph
langserve

@dosubot dosubot bot added Ɑ: Runnables Related to Runnables 🔌: openai Primarily related to OpenAI integrations 🤖:improvement Medium size change to existing code to handle new use-cases labels Mar 19, 2024
@SimonStanley1
Copy link
Author

@liugddx
Copy link
Contributor

liugddx commented Mar 19, 2024

There is already a PR that solves this problem

@SimonStanley1
Copy link
Author

prefect thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:improvement Medium size change to existing code to handle new use-cases 🔌: openai Primarily related to OpenAI integrations Ɑ: Runnables Related to Runnables
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants