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

ChatGPT Agent V2 #2086

Closed
wants to merge 77 commits into from
Closed

Conversation

Future-Outlier
Copy link
Member

@Future-Outlier Future-Outlier commented Jan 3, 2024

Tracking issue

flyteorg/flyte#3936

Why are the changes needed?

We want to support chatgpt agent and provide example for users to develop sync agent.

What changes were proposed in this pull request?

  • add openai-chatgpt plugin

How was this patch tested?

Setup process

  1. Set up my local single binary environment. (use pyflyte serve agent)
  2. Build a docker image with sync agent proto and chatgpt agent's gitsha.
  3. Test the chatgpt task in both local and remote scenarios.
tasks:
  task-plugins:
    enabled-plugins:
      - container
      - sidecar
      - K8S-ARRAY
      - agent-service
      
    default-for-task-types:
      chatgpt: agent-service
      custom_task: agent-service
      container: container
      container_array: K8S-ARRAY

plugins:
  agent-service:
    supportedTaskTypes:
      - sensor
      - spark
      - default_task
      - custom_task
      - chatgpt
      - sensor
      - airflow
    defaultAgent:
      endpoint: "dns:///localhost:8000"
      insecure: true
      timeouts:
        GetTask: 100s
      defaultTimeout: 100s
FROM python:3.9-slim-buster
USER root
WORKDIR /root
ENV PYTHONPATH /root
RUN apt-get update && apt-get install build-essential -y
RUN apt-get install git -y

RUN pip install -U git+https://github.com/Future-Outlier/flytekit.git@b058a985a43ffe8c27fd167d36cbf834d4c1732b#subdirectory=plugins/flytekit-openai

RUN pip install -U git+https://github.com/flyteorg/flyte.git@79534d163929734a6b8113c93bb0291ee84b9f4b#subdirectory=flyteidl

RUN pip install -U git+https://github.com/Future-Outlier/flytekit.git@b058a985a43ffe8c27fd167d36cbf834d4c1732b
from flytekit import task, workflow
from flytekitplugins.chatgpt import ChatGPTTask, ChatGPTConfig

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

chatgpt_big_job = ChatGPTTask(
    name="chatgpt gpt-4",
    openai_organization="org-NayNG68kGnVXMJ8Ak4PMgQv7",
    chatgpt_config={
            "model": "gpt-4",
            "temperature": 0.7,
    },
)

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

if __name__ == "__main__":
    print(wf(message="hi"))

Screenshots

Local Scenario

python chatgpt_chain.py

image

Remote Scenario

pyflyte run --remote --image futureoutlier/flytekit:chatgpt-0104 chatgpt_chain.py wf --message hi

image
image
image
image

Check all the applicable boxes

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

Related PRs

#1822
#2085

Docs link

Copy link

codecov bot commented Jan 3, 2024

Codecov Report

Attention: Patch coverage is 86.97917% with 50 lines in your changes are missing coverage. Please review.

Project coverage is 84.59%. Comparing base (7794d3a) to head (6c36d35).
Report is 8 commits behind head on master.

Files Patch % Lines
flytekit/extend/backend/agent_service.py 58.90% 24 Missing and 6 partials ⚠️
flytekit/extend/backend/base_agent.py 89.76% 5 Missing and 8 partials ⚠️
.../flytekit-airflow/flytekitplugins/airflow/agent.py 84.21% 3 Missing ⚠️
...gins/flytekit-spark/flytekitplugins/spark/agent.py 87.50% 2 Missing ⚠️
...lytekit-bigquery/flytekitplugins/bigquery/agent.py 95.00% 1 Missing ⚠️
...tekit-snowflake/flytekitplugins/snowflake/agent.py 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2086      +/-   ##
==========================================
- Coverage   85.53%   84.59%   -0.94%     
==========================================
  Files         309      315       +6     
  Lines       23460    24114     +654     
  Branches     3630     3658      +28     
==========================================
+ Hits        20066    20400     +334     
- Misses       2752     3094     +342     
+ Partials      642      620      -22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Future-Outlier Future-Outlier mentioned this pull request Jan 3, 2024
3 tasks
@Future-Outlier Future-Outlier marked this pull request as ready for review January 4, 2024 09:06
_clean_up_task: coroutine = None
_agent: AgentBase = None
_entity: PythonTask = None
_ctx: FlyteContext = FlyteContext.current_context()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we not use current context here?

Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
pingsutw and others added 5 commits February 20, 2024 01:44
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Feb 20, 2024
@Future-Outlier
Copy link
Member Author

It works well.

2024-02-20.22-09-07.mp4

pingsutw and others added 19 commits February 20, 2024 12:20
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Kevin Su <[email protected]>
Signed-off-by: Future-Outlier <[email protected]>
@Future-Outlier Future-Outlier mentioned this pull request Feb 23, 2024
3 tasks
@Future-Outlier
Copy link
Member Author

The process to merge master branch is too painful, I am going to open a new branch, sorry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XXL This PR changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants