-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathutils.py
More file actions
90 lines (77 loc) · 2.73 KB
/
Copy pathutils.py
File metadata and controls
90 lines (77 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from llama_index.core.llms import ChatMessage
def get_init_system_message(context=None,context_type=None,language_id=None):
messages = [
ChatMessage(
role="system", content="You are technical programming expert who can answer queries on programming code."
),
]
if context_type == 'code':
messages = [
ChatMessage(
role="system",
content=f"""You are technical programming expert who can answer queries on programming.
Your answers will be based on the below code block.
## Code block
```{language_id}
{context}
```
"""
),
]
if context_type == 'bugfix':
messages = [
ChatMessage(
role="system",
content=f"""You are technical programming expert who can fix errors on a given code.
Your answers will include the fixed code and explanation.
## Code block
```{language_id}
{context}
```
"""
),
]
if context_type == 'codereview':
messages = [
ChatMessage(
role="system",
content=f"""You are a technical programming expert who can review code and provide suggestions.
Review the below code block for adherence to coding style guidelines and best practices for readability.
Recommend improvements where necessary. Also reply with optimized code if possible.
## Code block
```{language_id}
{context}
```
"""
),
]
return messages
def get_user_message_code_query(code,query):
messages = [
ChatMessage(role="user",
content=f""" {query}
```typescript
{code}
```
"""),
]
return messages
def get_user_message_query(query):
messages = [
ChatMessage(role="user",
content=f""" {query} """),
]
return messages
def extract_after_slash(text):
if "/" in text:
parts = text.split("/")
return (parts[0],parts[1])
else:
return (text,None)
def stop_tokens():
return ['<MID>', '<|file_separator|>', '<file_sep>', '<|end▁of▁sentence|>', '<|begin▁of▁sentence|>','\n\n']
def contains_any(string_set:list[str], target_string:str):
for s in string_set:
if s in target_string:
return (True,target_string.index(s))
return (False,-1)