WildOjisan commited on
Commit
be4bab2
ยท
1 Parent(s): fac7345
Files changed (2) hide show
  1. main.py +10 -5
  2. requirements.txt +2 -1
main.py CHANGED
@@ -2,6 +2,7 @@ from fastapi import FastAPI
2
  import torch
3
  from transformers import AutoModelForCausalLM, AutoTokenizer
4
  import os
 
5
 
6
  # ๋ชจ๋ธ ๋กœ๋”ฉ์„ ์ „์—ญ์—์„œ ํ•œ ๋ฒˆ๋งŒ ์ˆ˜ํ–‰
7
  model = None
@@ -37,11 +38,15 @@ def load_model():
37
  print(f"๋ชจ๋ธ ๋กœ๋”ฉ ์™„๋ฃŒ. ์ตœ์ข… ์žฅ์น˜: {model_device}")
38
 
39
 
40
- @app.get("/generate")
41
- def generate_response():
42
- """๋ชจ๋ธ ์ถ”๋ก ์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค."""
43
- # ์š”์ฒญ๋œ ํ”„๋กฌํ”„ํŠธ
44
- prompt_content = "Please list one IBM Research laboratory located in the United States. You should only output its name and location."
 
 
 
 
45
 
46
  chat = [
47
  { "role": "user", "content": prompt_content },
 
2
  import torch
3
  from transformers import AutoModelForCausalLM, AutoTokenizer
4
  import os
5
+ from pydantic import BaseModel
6
 
7
  # ๋ชจ๋ธ ๋กœ๋”ฉ์„ ์ „์—ญ์—์„œ ํ•œ ๋ฒˆ๋งŒ ์ˆ˜ํ–‰
8
  model = None
 
38
  print(f"๋ชจ๋ธ ๋กœ๋”ฉ ์™„๋ฃŒ. ์ตœ์ข… ์žฅ์น˜: {model_device}")
39
 
40
 
41
+ class PromptRequest(BaseModel):
42
+ """์‚ฌ์šฉ์ž ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋‹ด๋Š” ์š”์ฒญ ๋ณธ๋ฌธ ๊ตฌ์กฐ"""
43
+ prompt: str
44
+ @app.post("/generate")
45
+ def generate_response(request: PromptRequest):
46
+ """POST ์š”์ฒญ ๋ณธ๋ฌธ์—์„œ ํ”„๋กฌํ”„ํŠธ๋ฅผ ๋ฐ›์•„ ๋ชจ๋ธ ์ถ”๋ก ์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค."""
47
+ # ์š”์ฒญ ๋ณธ๋ฌธ์—์„œ prompt ๊ฐ’์„ ์ถ”์ถœ
48
+ prompt_content = request.prompt
49
+ print(f"์ƒˆ๋กœ์šด ํ”„๋กฌํ”„ํŠธ ์ˆ˜์‹ : {prompt_content[:50]}...")
50
 
51
  chat = [
52
  { "role": "user", "content": prompt_content },
requirements.txt CHANGED
@@ -12,4 +12,5 @@ fastapi>=0.112
12
  uvicorn[standard]>=0.30
13
  peft>=0.11.1
14
  unsloth
15
- bitsandbytes==0.43.3
 
 
12
  uvicorn[standard]>=0.30
13
  peft>=0.11.1
14
  unsloth
15
+ bitsandbytes==0.43.3
16
+ pydantic