-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Robch/2310 oct22 chat proto func (#64)
* initial ability to call chat protocol function * updated function_call script to work with copilots from aistudio-copilot-sample repo oct-refresh branch * refactor environment helpers * refactor; set environment before calling chat functions * move file * update help * move file again * added --question support to `ai chat`
- Loading branch information
Showing
7 changed files
with
320 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import os | ||
from typing import Any, List | ||
|
||
def chat_completion(question: str) -> List[str]: | ||
answers = [] | ||
|
||
# Implement a switch statement for various questions | ||
if question == "what is your name?": | ||
answers.append("My name is ChatGPT.") | ||
elif question == "what is the capital of France?": | ||
answers.append("The capital of France is Paris.") | ||
elif question == "what is 2 + 2?": | ||
answers.append("2 + 2 is 4.") | ||
elif question == "tell me a joke": | ||
answers.append("Why did the chicken cross the road? To get to the other side!") | ||
elif question == "show environment variables": | ||
answers.append("Here are the environment variables:\n\n" + "\n".join([f" {k}: {v}" for k, v in os.environ.items()])) | ||
else: | ||
answers.append("I don't know the answer to that question.") | ||
return answers | ||
|
||
return answers | ||
|
||
async def async_chat_completion(messages: list[dict] = None, stream: bool = False, | ||
session_state: Any = None, context: dict[str, Any] = {}): | ||
|
||
if (messages is None): | ||
return chat_completion(question) | ||
|
||
print(messages) | ||
|
||
# get search documents for the last user message in the conversation | ||
question = messages[-1]["content"] | ||
|
||
return chat_completion(question) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.