代做INFO7500 Homework 7: Add NL Interactivity to your Uniswap UI代写数据库编程

Homework 7: Add NL Interactivity to your Uniswap UI

Goal

●   Add natural language interactivity to the Uniswap UI you built in homework 6.

Natural language instructions

○    Using natural language, a user should be able to:

■    deposit, redeem, or swap

●    Examples:

○    “swap 10 USDC for eth”

■    LLM should convert this to call of:

●    swapExactTokensForTokens(

○    uint amountIn,

○    uint amountOutMin,

○    address[] calldata path,

○    address to,

○    uint deadline)

○    “deposit 5 Tether and 3 wbtc”

●    Sequence of steps upon user entering NL instruction (NLI):

○    Convert NLI to a structure representation SR.

■   Text-to-sql is an example of this operation:

●    convert from natural language to structured data

■   function calling is another example

●    convert from natural language to API

○    Convert the SR into an Ethereum transaction TX.

○    Sign the TX with private key (eth_signTransaction)

○    Submit the signed TX to the Ethereum JSON RPC call (eth_sendRawTransaction).

●    Metamask should open automatically to ask the user’s approval.

■   Ask app-specific data analysis questions (in contrast to low level chain-specific

data analysis questions like we did with bitcoin) about the Uniswap pools based  on the Uniswap event data. Use the events emitted by the contracts for the data analysis.

●    Examples:

○    “what are the reserves of the tether-eth pool”

○    “how many swaps have there been so far today”

Open source LLM:

○    User should have the option to use their own open source LLM. The UI should have a text box that a user can use to specify the URL for an open source model.

○   Your tests should show results on an open source model and OpenAI, side by side.

Test cases (a.k.a. test set”, or task evaluation in AI):

○   Ten test cases of varying difficulty that show how your system is able to answer natural language questions and follow natural language instructions for Uniswap data.

■    Diversity is critical to the quality of the test suite.

●    Each test case should be significantly different from others.

●    Collectively they should cover the space of possible user NL instructions.

■    Critical for quantifying current level of performance

○   Ten very hard test cases that are so hard that the system is not able to answer correctly. The purpose of this is to find the limit of what’s possible for this task.

■   The test cases should be significantly different from each other.

■    Critical for defining the scope of future improvements.

●    Host your site publicly.

Prepare an in-class presentation/walkthrough/demo for your UI on the due date.

NOTE: The submission will be at midnight, but the demo will be during class earlier that day.

Deliverable

1.    A publicly hosted URL to your UI that achieves the goals above.

2.    Code repo

3.    An “task evaluation” page in your UI that enables execution of your twenty test cases.

a.    For each test case:

i.       The natural language instruction

ii.       The correct answer for the test case.

iii.       A button that executes the test case.

iv.       The output from an open source model

v.       The output from OpenAI

b.    This evaluation page should allow users to add more test cases through the UI.

i.       Does not need to be persistent.

Hints

●    Learn about function calling (aka tool use). Consider whether function calling is easier to use than text-to-sql for this application.

●    Open source models may not work as well as OpenAI out of the box. You may need to try

advanced methods (e.g. chain of thought reasoning, etc) to get open source models to perform. well for this task.

●    Focus on getting your system working end-to-end first before making it better and more

accurate. Think about how to structure your work so that you can link all the pieces together with minimal effort.

○    For example:

■    Figure out how to get your system working for just one simple test case using only OpenAI:

●    “swap 10 USDC for eth”

■    Deploy your system to a public URL.

■    Now you have a minimal working system and now it's easier to back and focus on making each part better (e.g. adding open source models).

Guidelines

●   You may use any UI framework or library.

●   You may write a server for making the LLM calls, if you prefer, instead of doing it in the UI.

Function Calling Example

completion = client.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": "What is the weather like in Paris today?"}], tools=tools )

OpenAI’s response:

[ChatCompletionMessageToolCall (id= 'call_QahB4aCsj8i4veQROOIio2Q4 ', function=Function (arguments= '{"location":"Paris, France"} ',

name= 'get_weather '), type= 'function ')]

Means that OpenAI is telling us to invoke get_weather ( “Paris, France”) in order to get the answer to this question.

Approach

What prompt to use?

Suppose:

User: “swap 10eth for usdc .

Possible options in increasing levels of accuracy:

1.   The prompt is exactly the instruction from the user.

a.   Example:

i.      Thus, the OpenAI API request would be just:

1.   Message: “swap 10eth for usdc .

2.   Keep the prompt empty, but also now add a set of tools.

a.   Example:

i.      Message: swap 10 eth for usdc .

ii.      Tools:

1. swap (num_tokens_in, in_token_type, out_token_type)

a. in_token_type

i.  description: the name of the token that we are swapping into the AMM.

b. out_token_type

i.  description: the name of the token that we are swapping out of the AMM.

Issue to address:

●   The tool calling gives you the symbols or the names for the tokens, but the Uniswap function actually needs addresses.

●    Converting the tool call function signature into the actual Uniswap call:

○    UniswapRouter.swapExactTokensForTokens (

■    uint amountIn,

■    uint amountOutMin,

■    address [] calldata path,

■    address to,

■    uint deadline)

○    UniswapRouter has many different swap functions. We don’t need to use all of them.

■    We can just pick one.

○   This function is part of the UniswapRouter (not the UniswapPair)

■    UniswapPair has low-level interface to the AMM

●    Expects several setup activities before the call actually works.

■    UniswapRouter does this setup for us.

○   The amountIn parameter is straightforward -- just copy value from tool call.

○   The amountOutMin can be hardwired to 0, which means no constraint how many token we get back.

■   Alternative, adjust tool call signature to mirror exactly the swapExactTokensForTokens signature.

○   A more interesting approach is to:

Aspirational: Write general purpose code to convert an ABI json for a contract, into the json schema tool call Open API expects.

●    Part that needs some creativity: where to get the descriptions for the parameters of functions specified in the ABI.

○    One option: give the json schema with empty descriptions to the LLM and ask it to ll it in based on its knowledge.

■    Can increase chance of success:

●    In the prompt we can give it the Solidity contract

○   Through code understanding, it may get some descriptions more accurately than if it just relied on its own internal knowledge

○   Through embedded comments in the Solidity contracts.

●    Question: where to do the LLM call?

○    Ideally in the browser, because it says more decentralized.

○    But there are advantages to doing it server side,especially if you are building a product:

■    But can also just send logs back of user actions to address this. ○ https://webllm.mlc.ai/

■    In-browser inference (as opposed to in-browser API call)

■   App remains truly decentralized

■    Hard part:

●    May not work for cpu, in which you can default to API call

●    even tho if they do have the gpu, may not be powerful enough or fast enough for the types of prompts we have.

●   the main issue is GPU memory. To host powerful models, you need a lot of GPU memory. Otherwise you are limited to small models.

○    Microsoft has Phi series specifically for running smaller models.

●    Sending the transaction (already did this step in hw6)

○    Now we have the solidity function call, we can create a transaction using web3 library, which can then also be used to:

■    Sign the TX with private key (eth_signTransaction,

■    Submit the signed TX to the Ethereum JSON RPC call (eth_sendRawTransaction).

●    Data analysis questions

○    Option #1: Ask OpenAI the question from the user directly.

○    Option #2: One way: same text-to-sql setup, but for event (log) data from Uniswap contracts.

■    “emit *” writes easy to process logs on different action performed on Uniswap (e.g. swaps, deposit, etcs)

■    Read these events through the RPC json for ethereum for uniswap contracts and store them into sqlite

○    Option #3:  Just give OpenAI the eth_getLogs directly and have it write code to call eth_getLogs

○    Option #4: Option #3, but help it with the decoding process.

Example RPC call:

{

"jsonrpc": "2.0", "id": 0,

"method": "eth_getLogs", "params": [

{

"fromBlock": "0x429d3b",

"toBlock": "0x429d3b",

"address": "0xb59f67a8bff5d8cd03f6ac17265c550ed8f33907",

"topics": [

"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",

"0x00000000000000000000000000b46c2526e227482e2ebb8f4c69e4674d262e75",

"0x00000000000000000000000054a2d42a40f51259dedd1978f6c118a0f0eff078"

]

}

]

}

Decoding eth_getLogs into Solidity

Note: return data from eth_getLogs hasn’t been decoded into Solidity concepts. Will need to do that to

decode these bytes into higher level concepts such as:

emit Mint(msg.sender, amount0, amount1);

How can we do this decoding?

Option 1: Ask OpenAI. It may have learned how to decode from examples on the Internet.

Option 2: Ask OpenAI to write code to decode it.

Give it the Solidity contract and the json rpc call.

Option 3: Find an existing library to do the decoding.

Next issue: how to convert natural language instruction into code that calls our tools.

Ask OpenAI: answer the user’s  data analysis question about Uniswap. The question is at the bottom of this prompt. Write code to You may use these functions to do, assume they’ve been implemented.

To-do:

●    Check why the enum validation in the schema wasn’t honored by OpenAI tool calling




热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图