Skip to content

Commit

Permalink
add system prompt as parameter to ask
Browse files Browse the repository at this point in the history
  • Loading branch information
gptlang committed Feb 1, 2024
1 parent b3e3284 commit a298f33
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions rplugin/python3/copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,12 @@ def authenticate(self):

self.token = self.session.get(url, headers=headers).json()

def ask(self, prompt: str, code: str, language: str = ""):
def ask(self, system_prompt: str, prompt: str, code: str, language: str = ""):
# If expired, reauthenticate
if self.token.get("expires_at") <= round(time.time()):
self.authenticate()
url = "https://api.githubcopilot.com/chat/completions"
self.chat_history.append(typings.Message(prompt, "user"))
system_prompt = prompts.COPILOT_INSTRUCTIONS
if prompt == prompts.FIX_SHORTCUT:
system_prompt = prompts.COPILOT_FIX
elif prompt == prompts.TEST_SHORTCUT:
system_prompt = prompts.COPILOT_TESTS
elif prompt == prompts.EXPLAIN_SHORTCUT:
system_prompt = prompts.COPILOT_EXPLAIN
data = utilities.generate_request(
self.chat_history, code, language, system_prompt=system_prompt
)
Expand Down Expand Up @@ -141,7 +134,7 @@ def _get_embeddings(self, inputs: list[typings.FileExtract]):
if i + 18 > len(inputs):
data = utilities.generate_embedding_request(inputs[i:])
else:
data = utilities.generate_embedding_request(inputs[i : i + 18])
data = utilities.generate_embedding_request(inputs[i: i + 18])
response = self.session.post(url, headers=self._headers(), json=data).json()
if "data" not in response:
raise Exception(f"Error fetching embeddings: {response}")
Expand Down

0 comments on commit a298f33

Please sign in to comment.