-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractKeyword.py
More file actions
31 lines (26 loc) · 1.27 KB
/
Copy pathextractKeyword.py
File metadata and controls
31 lines (26 loc) · 1.27 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
from ollama import AsyncClient
async def call_ollama_async(prompt, question):
model_name = "qwen2.5-coder:7b"
client = AsyncClient()
message = {"role": "user", "content": f"{prompt}\n{question}"}
response = await client.chat(
model=model_name,
messages=[message],
stream=False,
)
return response
async def extract_prompt_elements_async(prompt):
initial_prompt = (
"You are now a keyword extractor for code-related content. "
"You have excellent text analysis capabilities and can identify potential code elements in a prompt. "
"Your task is to extract keywords that are likely to appear in code from the prompt I provide. "
"Return the result as a Python list only—do not include any additional output or explanations. "
"For example, in the prompt 'I want to fix my method getAddress', 'getAddress' is likely a code-related term, "
"so the output should be ['getAddress']. If there are no code-related keywords, return ['none']. "
"Now, I will give you a prompt. Please provide your answer:"
)
question = prompt
res = await call_ollama_async(initial_prompt, question)
content = res['message']['content']
content = content.replace('```python', '').replace('```', '').strip()
return content