forked from antrea-io/antrea
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Shuyang Xin <[email protected]>
- Loading branch information
1 parent
74e02ae
commit 74b73c5
Showing
4 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: LangChain Issue Processor | ||
|
||
on: | ||
issues: | ||
types: [opened, reopened] | ||
|
||
jobs: | ||
process-issue: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
- name: Install dependencies | ||
run: | | ||
pip install langchain openai langchain[docarray] | ||
- name: Run process.py | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | ||
run: | | ||
SCRIPT_OUTPUT=$(python ai/issue_answer.py --github-token $GITHUB_TOKEN --openai-token $OPENAI_API_KEY --issue-number ${{ github.event.issue.number }}) | ||
echo "$SCRIPT_OUTPUT" | ||
echo "SCRIPT_OUTPUT=$SCRIPT_OUTPUT" >> $GITHUB_ENV | ||
echo "${{env.SCRIPT_OUTPUT}}" | ||
- name: comment result | ||
uses: actions/github-script@v5 | ||
with: | ||
script: | | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: `${{env.SCRIPT_OUTPUT}}`, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: LangChain Label Processor | ||
|
||
on: | ||
issues: | ||
types: [opened, reopened] | ||
|
||
jobs: | ||
process-issue: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
- name: Install dependencies | ||
run: | | ||
pip install langchain openai | ||
- name: Run process.py | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} | ||
run: | | ||
LABEL_OUTPUT=$(python ai/label_answer.py --github-token $GITHUB_TOKEN --openai-token $OPENAI_API_KEY --issue-number ${{ github.event.issue.number }}) | ||
echo "LABEL_OUTPUT=$LABEL_OUTPUT" >> $GITHUB_ENV | ||
- name: comment result | ||
uses: actions/github-script@v5 | ||
with: | ||
script: | | ||
const labelsToAdd = '${{ env.LABEL_OUTPUT }}'.replace(/'/g, '').split(','); | ||
github.rest.issues.addLabels({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: labelsToAdd, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from langchain.document_loaders.github import GitHubIssuesLoader | ||
from langchain.chat_models import ChatOpenAI | ||
from langchain.prompts import ChatPromptTemplate | ||
from langchain.schema.output_parser import StrOutputParser | ||
from langchain.schema.runnable import RunnableParallel, RunnablePassthrough | ||
from langchain.vectorstores import DocArrayInMemorySearch | ||
from langchain.embeddings import OpenAIEmbeddings | ||
import argparse | ||
|
||
def parse_arguments(): | ||
parser = argparse.ArgumentParser(description="Your program description.") | ||
parser.add_argument("--github-token", required=True, help="GitHub access token") | ||
parser.add_argument("--openai-token", required=True, help="OpenAI API key") | ||
parser.add_argument("--issue-number", required=True, help="Github Issue Number") | ||
return parser.parse_args() | ||
|
||
# Parse command line arguments | ||
args = parse_arguments() | ||
|
||
# Create an instance of the GitHubIssuesLoader class | ||
loader = GitHubIssuesLoader( | ||
repo="XinShuYang/antrea", | ||
owner="XinShuYang", | ||
access_token=args.github_token, | ||
include_prs=False, | ||
) | ||
|
||
# Load the issues of the repository | ||
issues = loader.load() | ||
|
||
issue_data = [] | ||
# Print the title and body of each issue | ||
for issue in issues: | ||
if issue.metadata["number"] == args.issue_number : | ||
issue_data.append({'title': issue.metadata['title'], 'body': issue.page_content}) | ||
|
||
vectorstore = DocArrayInMemorySearch.from_texts( | ||
["The random error of layer can be preemptively avoided by adding checksum verification", "When local storage is depleted, Docker won't be able to load images properly","Not only the unnecessary antrea-agent, antea-cni binaries, but also the whole OVS, iptables, suricata dependecies can be got rid of from antrea-controller image"], | ||
embedding=OpenAIEmbeddings(openai_api_key=args.openai_token), | ||
) | ||
retriever = vectorstore.as_retriever() | ||
|
||
template = """Analyze and give the solution of the github issue based only on the following context: | ||
{context} | ||
GITHUB ISSUE: {question} | ||
""" | ||
prompt = ChatPromptTemplate.from_template(template) | ||
model = ChatOpenAI(model_name="gpt-3.5-turbo", openai_api_key=args.openai_token) | ||
output_parser = StrOutputParser() | ||
setup_and_retrieval = RunnableParallel( | ||
{"context": retriever, "question": RunnablePassthrough()} | ||
) | ||
|
||
chain = setup_and_retrieval | prompt | model | output_parser | ||
|
||
result=chain.invoke(issue_data) | ||
|
||
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from langchain.document_loaders.github import GitHubIssuesLoader | ||
from langchain.chat_models import ChatOpenAI | ||
from langchain.prompts import ChatPromptTemplate | ||
from langchain.schema.output_parser import StrOutputParser | ||
from langchain.schema.runnable import RunnableParallel, RunnablePassthrough | ||
|
||
import argparse | ||
|
||
def parse_arguments(): | ||
parser = argparse.ArgumentParser(description="Your program description.") | ||
parser.add_argument("--github-token", required=True, help="GitHub access token") | ||
parser.add_argument("--openai-token", required=True, help="OpenAI API key") | ||
parser.add_argument("--issue-number", required=True, help="Github Issue Number") | ||
return parser.parse_args() | ||
|
||
# Parse command line arguments | ||
args = parse_arguments() | ||
|
||
# Create an instance of the GitHubIssuesLoader class | ||
loader = GitHubIssuesLoader( | ||
repo="XinShuYang/antrea", | ||
owner="XinShuYang", | ||
access_token=args.github_token, | ||
include_prs=False, | ||
) | ||
|
||
# Load the issues of the repository | ||
issues = loader.load() | ||
|
||
issue_data = [] | ||
# Print the title and body of each issue | ||
for issue in issues: | ||
if issue.metadata["number"] == args.issue_number : | ||
issue_data.append({'title': issue.metadata['title'], 'body': issue.page_content}) | ||
|
||
template = """You are an assistant for Antrea, a software that provides networking and security services for a Kubernetes cluster. Please only output the classification results, with the optional word list for classification results [ 'api', 'arm', 'agent', 'antctl', 'cni', 'octant-plugin', 'flow-visibility', 'monitoring', 'multi-cluster', 'interface', 'network-policy', 'ovs', 'provider', 'proxy', 'test', 'transit', 'security', 'build-release', 'linux', 'windows']. You can only select one or more words from these words as the output result, which are enclosed in quotation marks and connected by commas.: | ||
{context} | ||
""" | ||
prompt = ChatPromptTemplate.from_template(template) | ||
model = ChatOpenAI(model_name="ft:gpt-3.5-turbo-1106:hydsoft::8Mu1CgrH", openai_api_key=args.openai_token) | ||
output_parser = StrOutputParser() | ||
setup_and_retrieval = RunnableParallel( | ||
{"context": RunnablePassthrough()} | ||
) | ||
|
||
chain = setup_and_retrieval | prompt | model | output_parser | ||
|
||
result=chain.invoke(issue_data) | ||
|
||
print(result) |