Text Generation
Transformers
PyTorch
Safetensors
English
llama
unsloth
axolotl
conversational
text-generation-inference
Instructions to use dreamgen/opus-v1-34b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use dreamgen/opus-v1-34b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="dreamgen/opus-v1-34b") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("dreamgen/opus-v1-34b") model = AutoModelForCausalLM.from_pretrained("dreamgen/opus-v1-34b", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use dreamgen/opus-v1-34b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "dreamgen/opus-v1-34b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "dreamgen/opus-v1-34b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/dreamgen/opus-v1-34b
- SGLang
How to use dreamgen/opus-v1-34b with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "dreamgen/opus-v1-34b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "dreamgen/opus-v1-34b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "dreamgen/opus-v1-34b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "dreamgen/opus-v1-34b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Desktop
- Docker Model Runner
How to use dreamgen/opus-v1-34b with Docker Model Runner:
docker model run hf.co/dreamgen/opus-v1-34b
Download example/prompt/format.py from dreamgen/opus-v1-34b: direct link, hf CLI and curl.
- Browser
- Download file 2.73 kB
-
https://huggingface.co/dreamgen/opus-v1-34b/resolve/main/example/prompt/format.py
- Command line
-
hf download hf://dreamgen/opus-v1-34b/example/prompt/format.py
-
curl -L -o format.py https://huggingface.co/dreamgen/opus-v1-34b/resolve/main/example/prompt/format.py
2.73 kB
| # %% | |
| from typing import Optional, List | |
| from dataclasses import field, dataclass | |
| class OpusV1Turn: | |
| role: str | |
| content: str | |
| names: List[str] = field(default_factory=list) | |
| # If set to true, will not append <|im_end|>, so the model will continue the turn. | |
| # In RP you can for example use the following to force a specific character response: | |
| # role="text" | |
| # names=["Jack"] | |
| # open="true" | |
| open: bool = False | |
| class OpusV1Character: | |
| name: str | |
| description: str | |
| class OpusV1StorySystemPrompt: | |
| format: str = "prose" | |
| plot_description: str = "" | |
| style_description: str = "" | |
| characters: List[OpusV1Character] = field(default_factory=list) | |
| class OpusV1Prompt: | |
| story: Optional[OpusV1StorySystemPrompt] = None | |
| turns: List[OpusV1Turn] = field(default_factory=list) | |
| def format_opus_v1_prompt(prompt) -> str: | |
| turns = prompt.turns | |
| if prompt.story is not None: | |
| system = format_opus_v1_system_prompt(prompt.story) | |
| turns = [OpusV1Turn(role="system", content=system)] + turns | |
| parts = [] | |
| for i, turn in enumerate(turns): | |
| assert turn.role in ["user", "text", "system", "assistant"] | |
| assert turn.role != "system" or i == 0 | |
| is_last = i == len(turns) - 1 | |
| open = is_last and turn.open | |
| parts.append(format_turn(turn.role, turn.content, turn.names, open=open)) | |
| return "".join(parts) | |
| def format_turn( | |
| role: str, content: str, names: List[str] = [], open: bool = False | |
| ) -> str: | |
| im_start = "<|im_start|>" | |
| im_end = "<|im_end|>" | |
| body = im_start + role | |
| if len(names) > 0: | |
| body += f" names= {'; '.join(names)}" | |
| body += "\n" | |
| if open: | |
| return body + content.lstrip() | |
| else: | |
| return body + content.strip() + im_end + "\n" | |
| def format_opus_v1_system_prompt(prompt) -> str: | |
| format_text = "story" if prompt.format == "prose" else "role-play" | |
| system = f""" | |
| You are an intelligent, skilled, versatile writer. | |
| Your task is to write a {format_text} based on the information below. | |
| Write the {format_text} as if it's a book. | |
| """.strip() | |
| if len(prompt.plot_description) > 0: | |
| system += "\n\n\n## Plot description:\n\n" | |
| system += prompt.plot_description.strip() | |
| if len(prompt.style_description) > 0: | |
| system += "\n\n\n## Style description:\n\n" | |
| system += prompt.style_description.strip() | |
| if len(prompt.characters) > 0: | |
| system += "\n\n\n## Characters:\n\n" | |
| for character in prompt.characters: | |
| system += f"### {character.name}\n\n" | |
| system += character.description.strip() | |
| system += "\n\n" | |
| return system.strip() | |