Percy3822 commited on
Commit
50b6338
·
verified ·
1 Parent(s): 8cf880f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from typing import List, Literal
4
+
5
+ app = FastAPI(title="Python AI Stub")
6
+
7
+ class Cursor(BaseModel):
8
+ l: int
9
+ c: int
10
+
11
+ class Viewport(BaseModel):
12
+ start: int
13
+ end: int
14
+ text: str
15
+
16
+ class Diagnostic(BaseModel):
17
+ l: int
18
+ sev: str
19
+ msg: str
20
+
21
+ class Memory(BaseModel):
22
+ short: List[str] = []
23
+ sess: List[str] = []
24
+ proj: List[str] = []
25
+
26
+ class Inp(BaseModel):
27
+ intent: str
28
+ file: str
29
+ lang: str
30
+ cursor: Cursor
31
+ viewport: Viewport
32
+ diag: List[Diagnostic] = []
33
+ term: str = ""
34
+ mem: Memory = Memory()
35
+
36
+ class Need(BaseModel):
37
+ function: bool = False
38
+ xrefs: List[str] = []
39
+ page_ids: List[str] = []
40
+
41
+ class Out(BaseModel):
42
+ mode: Literal["patch","full","ask"]
43
+ patch: str = ""
44
+ full_text: str = ""
45
+ explanation: str = ""
46
+ confidence: float = 0.9
47
+ need: Need = Need()
48
+
49
+ @app.post("/code_help", response_model=Out)
50
+ def code_help(x: Inp):
51
+ before = x.viewport.text
52
+ if "print(reslt)" in before:
53
+ after = before.replace("print(reslt)","print(result)",1)
54
+ h_start = x.viewport.start
55
+ h_count = x.viewport.end - x.viewport.start + 1
56
+ patch = f"--- a/{x.file}\n+++ b/{x.file}\n@@ -{h_start},{h_count} +{h_start},{h_count} @@\n-{before}\n+{after}\n"
57
+ return Out(mode="patch", patch=patch, full_text="", explanation="Fixed misspelling: reslt -> result.", confidence=0.96)
58
+ return Out(mode="ask", explanation="Need more context.", confidence=0.6)