MCPcopy Create free account
hub / github.com/Alorse/copilot-to-api / chat_completion

Method chat_completion

copilot_client.py:78–107  ·  view source on GitHub ↗

Send a chat completion request

(self, messages: List[Dict[str, str]], options: Dict[str, Any] = None)

Source from the content-addressed store, hash-verified

76 }
77
78 def chat_completion(self, messages: List[Dict[str, str]], options: Dict[str, Any] = None) -> Dict[str, Any]:
79 """Send a chat completion request"""
80 self.ensure_valid_token()
81
82 if options is None:
83 options = {}
84
85 request_data = {
86 'messages': messages,
87 'max_tokens': options.get('max_tokens', 1000),
88 'temperature': options.get('temperature', 0.3),
89 'stream': options.get('stream', False)
90 }
91
92 headers = {
93 'authorization': f'Bearer {self.copilot_token}',
94 'Copilot-Integration-Id': 'vscode-chat',
95 'content-type': 'application/json'
96 }
97
98 response = requests.post(
99 'https://api.githubcopilot.com/chat/completions',
100 headers=headers,
101 json=request_data
102 )
103
104 return {
105 'status': response.status_code,
106 'data': response.json() if response.status_code == 200 else response.text
107 }
108
109
110def show_help():

Callers 1

mainFunction · 0.95

Calls 1

ensure_valid_tokenMethod · 0.95

Tested by

no test coverage detected