From 54828ab83662050caae05d8f57b4027252bdd9b6 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Mon, 17 Jun 2024 10:51:29 -0400 Subject: [PATCH] Remove Gemini testing script (#13143) This PR removes `script/gemini.py`, which just looks like it was used for initially testing the Gemini API. Now that it's built into collab as a completion provider, it doesn't seem like we need this script anymore. Release Notes: - N/A --- script/gemini.py | 91 ------------------------------------------------ 1 file changed, 91 deletions(-) delete mode 100644 script/gemini.py diff --git a/script/gemini.py b/script/gemini.py deleted file mode 100644 index 7f3a7130de..0000000000 --- a/script/gemini.py +++ /dev/null @@ -1,91 +0,0 @@ -import subprocess -import json -import http.client -import mimetypes -import os - -def get_text_files(): - text_files = [] - # List all files tracked by Git - git_files_proc = subprocess.run(['git', 'ls-files'], stdout=subprocess.PIPE, text=True) - for file in git_files_proc.stdout.strip().split('\n'): - # Check MIME type for each file - mime_check_proc = subprocess.run(['file', '--mime', file], stdout=subprocess.PIPE, text=True) - if 'text' in mime_check_proc.stdout: - text_files.append(file) - - print(f"File count: {len(text_files)}") - - return text_files - -def get_file_contents(file): - # Read file content - with open(file, 'r') as f: - return f.read() - - -def main(): - GEMINI_API_KEY = os.environ.get('GEMINI_API_KEY') - - # Your prompt - prompt = "Document the data types and dataflow in this codebase in preparation to port a streaming implementation to rust:\n\n" - # Fetch all text files - text_files = get_text_files() - code_blocks = [] - for file in text_files: - file_contents = get_file_contents(file) - # Create a code block for each text file - code_blocks.append(f"\n`{file}`\n\n```{file_contents}```\n") - - # Construct the JSON payload - payload = json.dumps({ - "contents": [{ - "parts": [{ - "text": prompt + "".join(code_blocks) - }] - }] - }) - - # Prepare the HTTP connection - conn = http.client.HTTPSConnection("generativelanguage.googleapis.com") - - # Define headers - headers = { - 'Content-Type': 'application/json', - 'Content-Length': str(len(payload)) - } - - # Output the content length in bytes - print(f"Content Length in kilobytes: {len(payload.encode('utf-8')) / 1024:.2f} KB") - - - # Send a request to count the tokens - conn.request("POST", f"/v1beta/models/gemini-1.5-pro-latest:countTokens?key={GEMINI_API_KEY}", body=payload, headers=headers) - # Get the response - response = conn.getresponse() - if response.status == 200: - token_count = json.loads(response.read().decode('utf-8')).get('totalTokens') - print(f"Token count: {token_count}") - else: - print(f"Failed to get token count. Status code: {response.status}, Response body: {response.read().decode('utf-8')}") - - - # Prepare the HTTP connection - conn = http.client.HTTPSConnection("generativelanguage.googleapis.com") - conn.request("GET", f"/v1beta/models/gemini-1.5-pro-latest:streamGenerateContent?key={GEMINI_API_KEY}", body=payload, headers=headers) - - # Get the response in a streaming manner - response = conn.getresponse() - if response.status == 200: - print("Successfully sent the data to the API.") - # Read the response in chunks - while chunk := response.read(4096): - print(chunk.decode('utf-8')) - else: - print(f"Failed to send the data to the API. Status code: {response.status}, Response body: {response.read().decode('utf-8')}") - - # Close the connection - conn.close() - -if __name__ == "__main__": - main()