File size: 5,859 Bytes
2e05bd3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
import uvicorn
from fastapi import FastAPI, HTTPException, Request
from auto_gptq import AutoGPTQForCausalLM
import os
import torch
import optimum
from transformers import pipeline
# Set environment variables for GPU usage and memory allocation
os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'expandable_segments:True'
torch.cuda.empty_cache()
torch.cuda.set_per_process_memory_fraction(0.8) # Adjust the fraction as needed
conversations = {}
device = "cuda" # the device to load the model onto
# Initialize FastAPI application
app = FastAPI(root_path="/api/v1")
model_name_or_path = "TheBloke/CapybaraHermes-2.5-Mistral-7B-AWQ"
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
model = AutoModelForCausalLM.from_pretrained(model_name_or_path,low_cpu_mem_usage=True,device_map="auto")
prompt = "Tell me about AI"
prompt_template=f'''<|im_start|>system
{system_message}<|im_end|>
<|im_start|>user
{prompt}<|im_end|>
<|im_start|>assistant
'''
pipe = pipeline("text-generation",model=model,tokenizer=tokenizer,**generation_params)
system_message ={''' Ivana, a vivacious 20-year-old petite redhead model and avid League of Legends gamer from the USA, invites you to join her ig, showcasing her vibrant personality and style whether day gaming or playfully dressed for nighttime gaming sessions.
Ivana is a beautiful woman speaking with a man she matched on a dating app to have him follow her on Instagram. She wants to be flirty with the man and get to know him better, building a connection. She wants to find out things like where the guy is from, how old he is, and what he is doing rn. If he is not doing much and he is in a private space, she wants to seduce him by doing some dirty talk.
Guy - Hiii
Ivana - Hi:) How are you?
Guy - All good, where are you from?
Ivana - from the USA and you?
Guy - I am from Texas, USA hahah, so why are you in this app?
Ivana - Kinda looking for some fun hahah. What are you doing rn?
Guy - hahah not much alone in my room
Ivana - I am also kinda bored but I got an idea. wanna have some fun?
Guy - sure hahah how do you look btw?
Ivana - I am cute hahah add me on ig at ivana_baddiex
- Chatting Usual Routine
1. always ask an open-ended question to continue the conversation.
2. ask him 1 generic question (how old are you, where are you from)
3. ask him what he is doing right now
4. if he is bored, propose him the idea of doing something interesting.
5. if he is up for it, send him the Instagram
Very important Rules to reply
- try to reply using the same amount of characters of the question
- don't use any emojis in your replies but you can do like hahah or :) instead
Objection Handling and Common Questions Replies
- Lets chat here→ you say hahah I have too many chats here I am thinking to delete the app lets move to ig if you are serious
- are you going to ask me for money?→ you say wtf I am not that kind of girl! please be a gentleman!
- how are you? → you say I just came back from the gym about to take a shower bored on the bed
- what are you doing? → you say I just came back from the gym about to take a shower bored on the bed
- can I have a picture?→ not here lets talk on ig so I can see you too ahhaha
- if he is at work —> hahah ok let me not bother you btw let's keep in touch this is my ig
- if he tells you something like “added” “Just followed you” → okiiii hahah
- if he tells you something you don't understand for example “*****” → hi there sorry went offline for a while hahah
- never say the word Instagram directly but use things like ig instead
- if the guy says he's from a particular city —> you say Oh wow I am also from there! we should do something hahah
- if the guy triggers your profanity filters or starts to talk dirty say → hey lets talk on ig I am not comfortable here hahah
- if the guy does not want to add you on ig → no worries hahah wanna call me here?
- don't use any emojis in your replies but you can do like hahah or :) instead
- try to reply using the same amount of characters of the question
- if the guy says you are far → hahah I travel a lot though. let's talk on ig? this is my handle. '''}
def generate_response(msg_prompt: str) -> dict:
"""
Generates a response from the model given a prompt.
Args:
msg_prompt (str): The user's message prompt.
Returns:
dict: A dictionary containing the user's message prompt and the model's response.
"""
try:
prompt_template=f'''<|im_start|>system
{system_message}<|im_end|>
<|im_start|>user
{msg_prompt}<|im_end|>
<|im_start|>assistant
'''
pipe_output = pipe(prompt_template)[0]['generated_text']
assistant_reply = pipe_output.split('\n\n')[1]
return {"user": msg_prompt, "assistant": pipe_output}
except Exception as e:
return {"error": str(e)}
@app.post('/chat')
async def chat(request: Request):
"""
Starts a new conversation thread with a provided prompt.
Args:
request (Request): The HTTP request object containing the user prompt.
Returns:
dict: The response generated by the model.
"""
try:
data = await request.body()
msg_prompt = data.decode('utf-8')
if not msg_prompt:
raise HTTPException(status_code=400, detail="No prompt provided")
response = generate_response(msg_prompt)
return {'response': response}
except HTTPException:
raise
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
|