wandb / weave

Weave is a toolkit for developing AI-powered applications, built by Weights & Biases.
https://wandb.me/weave
Apache License 2.0
585 stars 40 forks source link

Weave not working with Flask #1684

Open EHxuban11 opened 1 month ago

EHxuban11 commented 1 month ago

If a function decorated with weave is called from a Flask endpoint, weave won't work.

CODE: `from flask import Flask import os from groq import Groq import weave

app = Flask(name)

@weave.op() def groq(user_message: str): client = Groq( api_key="***", ) chat_completion = client.chat.completions.create( messages=[ { "role": "user", "content": user_message, } ], model="mixtral-8x7b-32768", ) message = chat_completion.choices[0].message.content print(chat_completion.choices[0].message.content) return message

@app.route('/groq') def interact(): message = "Explain the importance of fast language models" return groq(message)

if name == 'main': weave.init("groq_weave")

groq("Dime los 10 mejores jugadores del mundo")

app.run(debug=True)`
jwlee64 commented 1 month ago

Hi @EHxuban11, I'm going to add a ticket to our backlog to add more docs around flask and fix this issue

Pixel-Panda commented 3 weeks ago

Would be nice to get a CodeSandbox of this. Its been impossible trying to get this repo working.

image
EHxuban11 commented 3 weeks ago

Would be nice to get a CodeSandbox of this. Its been impossible trying to get this repo working. image

Hello,

It works for me in python, maybe this helps you or other people to set up: `import os from groq import Groq import weave

@weave.op() def groq(user_message: str): client = Groq( api_key="API_KEY_HERE", )

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": user_message,
        }
    ],
    model="mixtral-8x7b-32768",
)
message = chat_completion.choices[0].message.content
print(chat_completion.choices[0].message.content)
return message

if name == 'main': weave.init("groq_weave") groq("Dime los 10 mejores jugadores de futbol del mundo") `

Pixel-Panda commented 3 weeks ago

Would be nice to get a CodeSandbox of this. Its been impossible trying to get this repo working. image

Hello,

It works for me in python, maybe this helps you or other people to set up: `import os from groq import Groq import weave

@weave.op() def groq(user_message: str): client = Groq( api_key="API_KEY_HERE", )

chat_completion = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": user_message,
        }
    ],
    model="mixtral-8x7b-32768",
)
message = chat_completion.choices[0].message.content
print(chat_completion.choices[0].message.content)
return message

if name == 'main': weave.init("groq_weave") groq("Dime los 10 mejores jugadores de futbol del mundo") `

I ran every command as instructed but i doubt that works in CodeSandbox.Also im not sure what part of this pasted code without any context as to where it goes is meant to solve the issue I posted. Looks like a pretty generic chat completion pair python script for mixtral.

It would help to get some kind of explanation or clarification about the snippet you sent (code snips alone arent exactly a response or solution to issues)

tssweeney commented 1 week ago

Hello all,

Thank you @EHxuban11 for the report and @Pixel-Panda for additional discussion. We have a bigger refactor going on right now to rework some context management which will play nicer with Flask (as well as other environments such as Google Colab). We will update with progress once this work is closer to delivery.

Thank you, Tim