flyte icon indicating copy to clipboard operation
flyte copied to clipboard

[flyte-core] Flyte Connection

Open pingsutw opened this issue 1 year ago • 2 comments

Tracking issue

https://github.com/flyteorg/flyte/issues/3936

Why are the changes needed?

It will allow users to pass different API_KEY to the chatGPT agent from flytepropeller

What changes were proposed in this pull request?

Agent client will read the secret from env or local file, and pass it to the agent server.

How was this patch tested?

local sandbox

Setup process

  1. Install flytekit and flyteidl
pip install "git+https://github.com/flyteorg/flytekit.git@76dfef0c89615bb28dfa1ead932544150d9c2cde"
pip install "git+https://github.com/flyteorg/flyte.git@d96975d0bc590b57e9205d81f4de9595a4bd1708#subdirectory=flyteidl"
  1. Update local config

Add below config to flyte-single-binary-local.yamlm and Add your API key to local env

export FLYTE_SECRET_OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>
externalResources:
  connections:
    chatgpt:
      secrets:
        openai_api_key: OPENAI_API_KEY
      configs:
        openai_organization: org-P2rdnZQry4Fw7Ak3vSpXEIrx
  1. Run Flyte cluster locally
cd flyte
pyflyte serve agent
make compile
flyte start --config flyte-single-binary-local.yaml
  1. Run a ChatGPT task
pyflyte run --remote flyte-example/chatgpt_example.py my_chatgpt_job --message hello
from flytekit import workflow, Secret
from flytekitplugins.chatgpt import ChatGPTTask

chatgpt_small_job = ChatGPTTask(
    name="3.5-turbo",
    openai_organization="org-P2rdnZQry4Fw7Ak3vSpXEIrx",
    connection="chatgpt",
    chatgpt_config={
        "model": "gpt-3.5-turbo",
        "temperature": 0.7,
    },
)


@workflow
def my_chatgpt_job(message: str) -> str:
    message = chatgpt_small_job(message=message)
    return message

Screenshots

Secret not found in propeller image

image
  • [x] I updated the documentation accordingly.
  • [x] All new and existing tests passed.
  • [x] All commits are signed-off.

Related PRs

https://github.com/flyteorg/flytekit/pull/2297

Docs link

NA

pingsutw avatar Mar 27 '24 20:03 pingsutw

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 66.98%. Comparing base (ce5eb03) to head (ad0a88f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5126      +/-   ##
==========================================
+ Coverage   60.99%   66.98%   +5.98%     
==========================================
  Files         794      278     -516     
  Lines       51475    12638   -38837     
==========================================
- Hits        31397     8465   -22932     
+ Misses      17186     3549   -13637     
+ Partials     2892      624    -2268     
Flag Coverage Δ
unittests-datacatalog 69.31% <ø> (ø)
unittests-flyteadmin ?
unittests-flytecopilot 17.79% <ø> (ø)
unittests-flytectl 68.03% <ø> (ø)
unittests-flyteidl 79.04% <ø> (ø)
unittests-flyteplugins ?
unittests-flytepropeller ?
unittests-flytestdlib 65.59% <ø> (+0.02%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Mar 27 '24 20:03 codecov[bot]

@pingsutw Would it be possible to merge the work of this PR with that of my PR? It seems like both include secrets in requests made to the agent, but this PR goes a step farther by resolving the value of secrets. On the other hand, my PR includes more details about which user is executing a task, which is also very useful for the agent to have.

noahjax avatar Mar 28 '24 17:03 noahjax