Giter Club home page Giter Club logo

Comments (1)

D-W- avatar D-W- commented on May 25, 2024

Hi @khchan, we don't support sub-flows and the promptflow package is designed to use in user's local machine instead of running in the cloud. load_flow has an assumption that all flow's connection should exist in user's local machine. But when executes in the cloud, those connections are not stored in the runtime machine. Which lead to the error above.

Here's a work around for your case: make connection a input and directly call built-in tool with that object.
Here's sample code:

from promptflow import load_flow, tool
from promptflow.connections import AzureOpenAIConnection

from jinja2 import Template
from promptflow.tools.aoai import chat

# The inputs section will change based on the arguments of the tool function, after you save the code
# Adding type to arguments and return value will help the system show the types properly
# Please update the function name/signature per need

# In Python tool you can do things like calling external services or
# pre/post processing of data, pretty much anything you want


@tool
def echo(input: str, my_connection: AzureOpenAIConnection) -> str:
    # subjoke = load_flow("./subjoke")
    # print(subjoke.context)
    # print(subjoke.context.connections)
    # subjoke_output = subjoke(topic=input, connection=my_connection)

    # instead of load sub flow as a flow, directly call tools here
    # load prompt
    with open("subjoke/joke.jinja2", "r", encoding="utf-8") as f:
        tmpl = Template(f.read(), trim_blocks=True, keep_trailing_newline=True)
        prompt = tmpl.render(topic=input)
    
    # directly call tool function with connection object
    output = chat(
        connection=my_connection,
        prompt=prompt,
        deployment_name="gpt-35-turbo",
        max_tokens=256,
        temperature=0.7,
    )
    return output

image

from promptflow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.