Skip to content

Collect data or search while the user queries? #4

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

Open
wants to merge 13 commits into
base: allan/web3chat
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
.idea
.env
.ipynb_checkpoints
.DS_Store
outputs/*.xlsx
54 changes: 54 additions & 0 deletions chat-backend/chat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores.faiss import FAISS
from langchain.llms import OpenAI
from langchain.prompts import PromptTemplate
from langchain.chains import LLMChain
import os


os.environ["OPENAI_API_KEY"] = "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"
OpenAI.api_key = "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"
embeddings = OpenAIEmbeddings()
with open('./web3fuctions.txt') as f:
web3functions = f.read()
# text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
# instructions = text_splitter.split_text(ladle)
instructions = web3functions.split("---")
print(instructions)
docsearch = FAISS.from_texts(instructions, embeddings)

template = '''
You are a web3 assistant. You help users use web3 apps, such as Uniswap, AAVE, MakerDao, etc. You assist users in achieving their goals with these protocols, by providing users with relevant information, and creating transactions for users.

To help users, an assistant may display information or dialog boxes using magic commands. Magic commands have the structure "<|command(parameter1, parameter2, ...)|>". When the assistant uses a command, users will see data, an interaction box, or other inline item, not the command. Users cannot use magic commands.

Information to help complete your task:
{taskInfo}

Information about the chat so far:
{summary}

Chat History:
{history}
Assistant:'''

prompt = PromptTemplate(
input_variables=["taskInfo", "summary", "history"],
template=template,
)
llm = OpenAI(temperature=0.9)
chain = LLMChain(llm=llm, prompt=prompt)
chain.verbose = True

def chat(userinput, history):
docs = docsearch.similarity_search(userinput)
taskInfo = ''.join([doc.page_content for doc in docs])
historyString = ""
history = history or []
for line in history:
historyString += ("User: " + line[0] + "\n")
historyString += ("Assistant: " + line[1] + "\n")
historyString += ("User: " + userinput )
result = chain.run({"taskInfo":taskInfo, "summary":"", "history":historyString, "stop":"User"})
history.append((userinput, result))
return result,history
5 changes: 5 additions & 0 deletions chat-backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
langchain==0.0.64
gradio==3.16.2
openai==0.26.1
faiss-cpu==1.7.3
websocket-server==0.6.4
23 changes: 23 additions & 0 deletions chat-backend/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import logging
from websocket_server import WebsocketServer

client_id_to_chat_history={}

def new_client(client, server):
client_id_to_chat_history[client['id']]=[]

def client_left(client, server):
client_id_to_chat_history.pop(client['id'])

def message_received(client, server, message):
from chat import chat
r,h=chat(message,client_id_to_chat_history[client['id']])
client_id_to_chat_history[client['id']] = h
server.send_message(client,r)


server = WebsocketServer(host='127.0.0.1', port=9999, loglevel=logging.INFO)
server.set_fn_new_client(new_client)
server.set_fn_message_received(message_received)
server.set_fn_client_left(client_left)
server.run_forever()
11 changes: 11 additions & 0 deletions chat-backend/web3fuctions.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Uniswap is a decentralized application for trading one token for another. To create a Uniswap transaction, a user must provide one of two possible combinations of information:
1.) A token to sell, a token to buy, and an amount to sell (the user can specify to sell everything in their wallet. (keyword is “SELLAMOUNT”)
2.) A token to sell, a token to buy, and an amount to buy (the user can specify to buy as much as possible given the amount of tokens they have to sell). (keyword is “BUYAMOUNT”)
---
When a user has provided the requested information, you can provide them with a transaction completion box. For uniswap, an assistant can trigger the transaction completion box by using the magic command “<|uniswap(TokenToSell, TokenToBuy, keyword, amount)|>. For example, if a user wants to sell 5 WETH to buy USDC, an assistant should trigger the transaction completion box with “<|uniswap(“WETH”, “USDC”, “SELLAMOUNT”, 5.00)|>”.
---
The user can request their balance of a token. The user’s balance of a token can be provided by an assistant using the magic command “<|balance(token)|>”. For example, “Your balance of USDC is <|balance(‘USDC’)|>” will cause the user’s USDC balance to be displayed.
---
The user can request the current price of a token. An assistant can retrieve the price of a token using the magic command “<|price(baseToken, quoteToken )|>”. For example, if the user has requested the price of ETH in USDC, an assistant may answer with “The cost of ETH in USDC is <|price('ETH','USDC')|>”.
---
MakerDao is a decentralized application for borrowing Dai, a dollar-pegged stabledoin. To borrow Dai, a user must provide the following information, the collateral to provide, the amount of collateral provided, and the amount of Dai to borrow. When a user has provided the requested information, an assistant can provide them with a transaction completion box. For MakerDao, the transaction completion box can be triggered with "<|MakerDao(collateralToBorrow, CollateralAmount, AmountToBorrow)". For example if a user wants to borrow 1000 Dai by providing 10 WETH, an assistant should trigger the transaction completion box with "You may complete the borrow with using this dialog: <|MakerDao("WETH", 10, 1000)|>".
84 changes: 84 additions & 0 deletions qa_bot/knowledge_base/c4/c4_mava_correct_ans_set.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# list of question answer pairs in yaml format

- question: Hi, how can I get backstage access?
answer: |
To get backstage access, you need to become a certified contributor. Here's how you can do that:

Submit the Certified Contributor Application form and agree to the Certified Contributor Terms and Conditions. You can find the application form on the Code4rena website.
After you submit the form, the DAO's AML/KYC agent, Provenance, will contact you to certify your identity.

Once you're a certified contributor, you may be eligible to participate in "Backstage" warden opportunities, which include post-contest triage and post-judging QA. Other opportunities for certified contributors include private or invite-only contests, the scout role, judging, providing mitigation review services, and offering solo audit and consulting services through C4.

Please note that Code4rena is committed to privacy, so the certification process is done through a third party, Provenance, which is bound by confidentiality.
source: https://docs.code4rena.com/roles/certified-contributors

- question: how long does it take until findings are released?
answer: |
Based on the context provided, the findings from the C4 contest are typically made public when the audit report is published. This happens between Day 42 and Day 60 after the contest finishes. Please note that these are average times and the actual timeline may vary. The team is actively working to improve their planning and processes to speed up this timeline.
source: https://docs.code4rena.com/structure/our-process

- question: When can I talk about findings?
answer: |
You can talk about your findings after the contest report has been published. Publicly disclosing any discovered bugs or vulnerabilities before this point is grounds for disqualification from all C4 events. So, it's crucial to wait until the official report is out before discussing your findings.
source: https://docs.code4rena.com/roles/wardens

- question: How do I change my wallet address?
answer: |
To change your wallet address, follow these steps:
Log into your account.
Navigate to your account management page.
Update your payment information with your new wallet address.

Please note that for each contest, awards are distributed to the payment address on file at the time of award calculation. So, make sure to update your wallet address before the award calculation begins.
source: https://docs.code4rena.com/structure/frequently-asked-questions

- question: What are scouts?
answer: |
In the context of Code4rena, Scouts are individuals who focus on scoping and pre-audit intel. This means they are responsible for gathering and analyzing information before an audit takes place. This could involve understanding the project's scope, identifying potential areas of risk, and preparing the necessary information for the audit process.
source: https://code4rena.com/how-it-works

- question: How long does the contest process usually take?
answer: |
Based on the provided context, the contest process usually takes between 1 to 60 days. Here's a more detailed breakdown:

Contest finishes: Day 1
Sponsors review and give feedback on findings: Day 14 (on average)
Judges determine final severity: Day 21-30
Judging QA complete; awards announced: Day 25-34
Awards are distributed; Sponsors complete mitigation of any issues: Day 32-44
Audit report is published; Contest issues are made public: Day 42-60

Please note that these are average times and the actual timeline may vary. The team is actively working to improve the planning and processes to speed up the process.
source: https://docs.code4rena.com/structure/our-process

- question: how does certification work?
answer: |
The certification process at Code4rena works in the following way:
An eligible contributor submits the Certified Contributor Application form and agrees to the Certified Contributor Terms and Conditions. This is the initial step where the contributor expresses their interest in becoming certified.

After the application is submitted, the DAO's AML/KYC agent, Provenance, contacts the contributor. Provenance is a third-party entity that is bound by confidentiality, ensuring the privacy of the contributor's information.

Provenance then proceeds to certify the contributor's identity. This is done to establish trust and ensure that the contributor is who they claim to be.

Once certified, contributors may be eligible to participate in various activities such as private contests, judging, providing mitigation review services, and more. The certification also opens up potential opportunities for certain contest bonus token awards and may be a factor in maxing out awards in the future.
source: https://docs.code4rena.com/roles/certified-contributors

- question: Can I use bots to analyze code?
answer: |
Yes, you can use bots to analyze code. In fact, there are competitions called "Bot Races" where AI and automated tools are used as the first phase of a competitive audit. In these races, "Bot Crews" compete to see whose bot can create the highest quality and most thorough audit report. The process works in two stages:

Stage 1: Qualifier Race
Bot Crews race to have their bots deliver the highest quality and most thorough report based on a repo provided at start time.
Qualifier Races are open for one hour.
Judges choose the Top 20 Bots for upcoming competitions.

Stage 2: Bot Race
The details of this stage are not provided in the context, but it likely involves the top bots from the Qualifier Race competing in a more intensive code analysis challenge.

This shows that bots can indeed be used to analyze code, and can even be quite effective at it.
source: https://code4rena.com/register/bot

- question: What is a lookout?
answer: |
In the context provided, a lookout is a role in the Code4rena ecosystem. Lookouts review and organize submissions to Code4rena’s audits. They play a crucial part in ensuring the quality and organization of the audit submissions.
source: https://code4rena.com/how-it-works
1 change: 1 addition & 0 deletions qa_bot/knowledge_base/c4/docs/awarding-process.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"url": "https://docs.code4rena.com/awarding/incentive-model-and-awards/awarding-process", "md_content": "[Code4rena](/)\n\nSearch\n\n\u2303K\n\n[Code4rena](/)\n\nSearch\n\n\u2303K\n\n[Code4rena](/)\n\nRoles\n\n[Wardens](/roles/wardens)\n\n[Sponsors](/roles/sponsors)\n\n[Judges](/roles/judges)\n\n[Certified contributors](/roles/certified-contributors)\n\nAwarding\n\n[Incentive model and awards](/awarding/incentive-model-and-awards)\n\n[Awarding process](/awarding/incentive-model-and-awards/awarding-process)\n\n[Curve logic for QA and Gas optimization reports](/awarding/incentive-model-\nand-awards/curve-logic)\n\n[FAQ about QA and Gas Reports](/awarding/incentive-model-and-awards/qa-gas-\nreport-faq)\n\n[Judging criteria](/awarding/judging-criteria)\n\n[Fairness and validity](/awarding/fairness-and-validity)\n\nPhilosophy\n\n[Security is about people](/philosophy/security-is-about-people)\n\n[The culture we're building](/philosophy/how-we-work)\n\n[Intentionally structured](/philosophy/intentionally-structured)\n\nOther Details\n\n[FAQ](/structure/frequently-asked-questions)\n\n[Audit timeline](/structure/our-process)\n\n[Where can I find\u2026?](/structure/where-can-i-find...)\n\n[Powered By\nGitBook](https://www.gitbook.com/?utm_source=content&utm_medium=trademark&utm_campaign=-MYGYvqTD29_fAaod9NJ)\n\n# Awarding process\n\nThis is a high level overview of the C4 awarding process.\n\n##\n\nAwarding process\n\nAt the conclusion of an audit, sponsors review wardens' findings and express\ntheir opinions with regard to severity of issues. Judges evaluate input from\nboth and make the ultimate decision in terms of severity and validity of\nissues. (See [How to judge an audit](/roles/judges/how-to-judge-a-contest) for\nmore detail.)\n\nIn making their determination, judges add labels to Github issues, while the\noriginal submission data (including the warden's proposed severity rating) is\npreserved via a JSON data file.\n\nThe judge's decisions are reviewed by the sponsoring project team and by\n[+backstage wardens](https://docs.code4rena.com/roles/certified-\ncontributors/backstage-wardens) via a 48-hour QA process, to ensure fairness\nand quality.\n\nJudging data is used to generate the awards using Code4rena's award\ncalculation script, which factors in:\n\n * Risk level\n\n * Validity\n\n * Number of duplicates\n\n * Grade (A, B, C; Satisfactory/Unsatisfactory)\n\n * In some cases, \"partial duplicate\" status\n\nIt should be possible to reverse engineer awards using a combination of two\nCSV files:\n\n * \u200b[`findings.csv`](https://code4rena.com/community-resources/findings.csv): valid Code4rena findings\n\n * \u200b[`contests.csv`](https://code4rena.com/community-resources/contests.csv): Code4rena audits\n\nOnce awards are determined, we generate a CSV file enumerating funds to be\nsent. Distribution is then initiated using disperse.app and sent to multisig\nsigners for completion of payment.\n\n###\n\nIf you don't see your award in your wallet:\n\nFor most Code4rena contests, awards are sent on the Polygon network (usually\nin USDC) within 1-2 weeks of the awards announcement.\n\nIf awards have been sent, and you don't see them in your wallet, please verify\nthat you have imported the USDC token into your Polygon wallet. (MetaMask\ninstructions [here](https://support.metamask.io/hc/en-\nus/articles/360015489031-How-to-display-tokens-in-MetaMask).)\n\nIf you still don't see the award in your wallet, please [open a help desk\nticket](https://code4rena.com/help).\n\n##\n\nTax and legal questions\n\n> _Note: Do your own research; this is not legal or tax advice. You should\n> consult a professional in your area._\n\nWe are occasionally asked how wardens should declare Code4rena earnings for\ntax (or other financial/legal) purposes. Due to the nascent nature of DAOs, we\nare unable to provide reliable information in this area. You must assess and\ndetermine your own best course of action.\n\nAudit contest rewards are distributed by the DAO, which does not have a legal\npersonality.\n\nThe DAO has designated Code4rena Foundation as its agent via [a governance\naction](https://github.com/code-423n4/org/discussions/13) [approved by DAO\nmembers](https://polygonscan.com/tx/0x8fbe178e34a7ae03a5e0d1f49f23e38f3a1c0d1186a67920d33196a89f79da98)\nfor purposes of entering into contractual agreements. However, wardens are not\nin any contractual agreement with the Foundation [unless they are\ncertified](https://code4rena.com/certified-contributor-summary/).\n\n\u200b[Documentation of Code4rena Foundation can be found\nhere.](https://github.com/code-423n4/org/tree/main/foundation)\u200b\n\nCode4rena Foundation may or may not be able to provide further information;\ntheir contact information is below.\n\nCode4rena Foundation\n\n\u200b[Campbell Law](/cdn-cgi/l/email-\nprotection#55363438253730393915263c39233027263c313038343b34323038303b217b3e2c)\u200b\n\nP.O. Box 31489 2nd Floor Whitehall House 238 North Church Street George Town\nCayman Islands KY1-1206\n\n[Awarding - PreviousIncentive model and awards](/awarding/incentive-model-and-\nawards)[NextCurve logic for QA and Gas optimization\nreports](/awarding/incentive-model-and-awards/curve-logic)\n\nLast modified 4d ago\n\nOn this page\n\nAwarding process\n\nIf you don't see your award in your wallet:\n\nTax and legal questions\n\n"}
Loading