daviddwlee84 / PromptFlow

Playing some Prompt Flow stuff

Home Page:https://promptflow.streamlit.app/Prompt_Flow_Scoring

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Prompt Flow

Playing some Prompt Flow stuff

Getting Started

Streamlit

pip install -r requirements.txt
# Optional
cp example.env .env
# Fill-in your keys
# ...
streamlit run Overview.py

Prompt Flow

Chat Example

pf flow init --flow ./flows/simple_chat --type chat
# Azure OpenAI
# https://stackoverflow.com/questions/72236557/how-do-i-read-a-env-file-from-a-ps1-script
# https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.4
# https://stackoverflow.com/questions/7760013/why-does-continue-behave-like-break-in-a-foreach-object
# Load .env and set environment variable in Powershell
Get-Content .env | foreach {
    $name, $value = $_.split('=')
    if ([string]::IsNullOrWhiteSpace($name) -or $name.Contains('#')) {
        return
    }
    Set-Content env:\$name $value
}

pf connection create --file ./flows/simple_chat/azure_openai.yaml --set api_key=$env:AZURE_OPENAI_KEY api_base=$env:AZURE_OPENAI_ENDPOINT/openai/deployments/$env:AZURE_OPENAI_DEPLOYMENT_NAME/chat/completions?api-version=$env:AZURE_OPENAI_VERSION --set api_version=$env:AZURE_OPENAI_VERSION --name open_ai_connection
# Interactive test
pf flow test --flow ./flows/simple_chat --interactive

# or

# Single run with default input
pf flow test --flow ./flows/simple_chat
# Serving API (serve a simple chat web UI)
pf flow serve --source ./flows/simple_chat --port 28080 --host localhost

$response = Invoke-WebRequest -URI http://localhost:28080/score -Body '{"question":"How are you?"}' -Method POST  -ContentType "application/json"
echo $response.Content
curl http://localhost:28080/score --data '{"question":"How are you?"}' -X POST  -H "Content-Type: application/json"

Todo

Resources

Trouble Shooting

promptflow 0.1.0b7.post1 requires openai<0.28.0,>=0.27.8, but you have openai 1.13.3 which is incompatible. / AttributeError: module 'openai' has no attribute 'BadRequestError'

pf.flow.test failed with UserErrorException: Exception: OpenAI API hits NotFoundError: Error code: 404 - {'error': {'code': 'DeploymentNotFound', 'message': 'The API deployment for this resource does not exist. If you created the deployment within the last 5 minutes, please wait a moment and try again.'}} [Error reference: https://platform.openai.com/docs/guides/error-codes/api-errors]

Basically your connection config are not set correctly

Seems the azure_openai.yaml is just a template, you don't need to change the file.

About

Playing some Prompt Flow stuff

https://promptflow.streamlit.app/Prompt_Flow_Scoring


Languages

Language:Jupyter Notebook 91.4%Language:Python 8.6%Language:Jinja 0.1%