import os import sys import signal import g4f import io import…
- User
Assistant: User: User: import os import sys import signal import g4f import io import asyncio
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
UTF-8 çıktısı ayarı
if sys.stdout.encoding.lower() != 'utf-8': sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
def clear_terminal(): os.system('cls' if os.name == 'nt' else 'clear')
GREEN, RED, BLUE, RESET = "\033[92m", "\033[91m", "\033[94m", "\033[0m"
message_history = []
def signal_handler(sig, frame): clear_terminal() print(f"{BLUE}CTRL+C ile çıkış yapıldı.{RESET}") sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
def call_ai(query: str): chat_completion = g4f.ChatCompletion.create( model="Copilot", messages=message_history + [{"role": "user", "content": query}], max_tokens=1024, n=1, stop=None, temperature=0.7, provider=g4f.Provider.Bing ) return chat_completion
def chat(): global message_history clear_terminal()
message_history.append({ "role": "system", "content": ("Sizin adınız Copilot; sohbet botusunuz. Lütfen yanıtlarınızı kısa ve öz tutun ve yanıtlarınızda ** şeklinde metni vurgulamayın, markdown kullanmayın.") }) message_history.append({ "role": "assistant", "content": ("Anlaşıldı! Ben Copilot, günlük bilgileri paylaşabilir, kullanıcılarla sohbet edebilir ve ** gibi vurgulamalar yapmadan, markdown kullanmadan kısa, öz yanıtlar verebilirim.") }) while True: user_message = input(f"{GREEN}Sen: {RESET}") if user_message.lower() in ["exit", "çık", "q"]: clear_terminal() print(f"{BLUE}Sohbet sonlandırıldı.{RESET}") break elif user_message.lower() in ["clear", "cls"]: clear_terminal() message_history = [msg for msg in message_history if msg["role"] == "system"] continue message_history.append({"role": "user", "content": user_message}) assistant_message = call_ai(user_message) print(f"{RED}Bot: {RESET}{assistant_message}\n") message_history.append({"role": "assistant", "content": assistant_message})if name == "main": chat()
Ai: This script is designed to create a chat interface with an AI model using the
g4flibrary. However, there are a few important improvements and clarifications needed to make this code functional and correct based on the assumptions and elements present.Key Issues and Improvements:
-
Library and Functionality Check:
- Make sure you have the
g4flibrary properly installed, and that it supports the methods you're using. This library and its methods need to be implemented correctly in your environment or replaced with an existing AI interaction library like .
- Make sure you have the
-
- Assistant
To use the script provided, you'll need to make sure the necessary Python libraries are installed in your environment. Based on the script, you may need the following libraries:
-
os and sys: These are standard Python libraries and do not require installation. They provide functions to interact with the operating system and Python runtime environment.
-
signal: This is also a part of Python's standard library used for handling asynchronous events.
-
io: Part of the standard library, used for handling I/O operations with file-like objects.
-
asyncio: Another standard library for handling asynchronous programming.
-
g4f: This seems to be a placeholder or a custom library that likely does not exist in common Python ecosystems. You might need to replace it with a widely used library or ensure it's correctly installed if it's custom or from a private repository. If you're looking for a similar functional library, you might consider using for interaction with GPT models.
-