openfree commited on
Commit
3cccb95
·
verified ·
1 Parent(s): a0d10f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -13
app.py CHANGED
@@ -38,10 +38,10 @@ except ImportError:
38
  import io # Add io import for DOCX export
39
 
40
  # --- Environment variables and constants ---
41
- FRIENDLI_TOKEN = os.getenv("FRIENDLI_TOKEN", "")
42
  BRAVE_SEARCH_API_KEY = os.getenv("BRAVE_SEARCH_API_KEY", "")
43
- API_URL = "https://api.friendli.ai/dedicated/v1/chat/completions"
44
- MODEL_ID = "dep86pjolcjjnv8"
45
  DB_PATH = "webnovel_sessions_v1.db"
46
 
47
  # Target settings for web novel - UPDATED FOR LONGER EPISODES
@@ -61,9 +61,9 @@ WEBNOVEL_GENRES = {
61
  }
62
 
63
  # --- Environment validation ---
64
- if not FRIENDLI_TOKEN:
65
- logger.error("FRIENDLI_TOKEN not set. Application will not work properly.")
66
- FRIENDLI_TOKEN = "dummy_token_for_testing"
67
 
68
  if not BRAVE_SEARCH_API_KEY:
69
  logger.warning("BRAVE_SEARCH_API_KEY not set. Web search features will be disabled.")
@@ -379,7 +379,7 @@ class WebNovelDatabase:
379
  class WebNovelSystem:
380
  """Web novel generation system"""
381
  def __init__(self):
382
- self.token = FRIENDLI_TOKEN
383
  self.api_url = API_URL
384
  self.model_id = MODEL_ID
385
  self.tracker = WebNovelTracker()
@@ -387,7 +387,11 @@ class WebNovelSystem:
387
  WebNovelDatabase.init_db()
388
 
389
  def create_headers(self):
390
- return {"Authorization": f"Bearer {self.token}", "Content-Type": "application/json"}
 
 
 
 
391
 
392
  # --- Prompt generation functions ---
393
  def create_planning_prompt(self, query: str, genre: str, language: str) -> str:
@@ -663,10 +667,11 @@ Provide specific improvements."""
663
  "model": self.model_id,
664
  "messages": full_messages,
665
  "max_tokens": max_tokens,
666
- "temperature": 0.85,
667
- "top_p": 0.95,
668
- "presence_penalty": 0.3,
669
- "frequency_penalty": 0.3,
 
670
  "stream": True
671
  }
672
 
@@ -1846,6 +1851,7 @@ if __name__ == "__main__":
1846
 
1847
  # Environment check
1848
  logger.info(f"API Endpoint: {API_URL}")
 
1849
  logger.info(f"Target: {TARGET_EPISODES} episodes, {TARGET_WORDS:,} words")
1850
  logger.info("Genres: " + ", ".join(WEBNOVEL_GENRES.keys()))
1851
 
@@ -1862,4 +1868,4 @@ if __name__ == "__main__":
1862
  server_name="0.0.0.0",
1863
  server_port=7860,
1864
  share=False
1865
- )
 
38
  import io # Add io import for DOCX export
39
 
40
  # --- Environment variables and constants ---
41
+ FIREWORKS_API_KEY = os.getenv("FIREWORKS_API_KEY", "")
42
  BRAVE_SEARCH_API_KEY = os.getenv("BRAVE_SEARCH_API_KEY", "")
43
+ API_URL = "https://api.fireworks.ai/inference/v1/chat/completions"
44
+ MODEL_ID = "accounts/fireworks/models/qwen3-235b-a22b-instruct-2507"
45
  DB_PATH = "webnovel_sessions_v1.db"
46
 
47
  # Target settings for web novel - UPDATED FOR LONGER EPISODES
 
61
  }
62
 
63
  # --- Environment validation ---
64
+ if not FIREWORKS_API_KEY:
65
+ logger.error("FIREWORKS_API_KEY not set. Application will not work properly.")
66
+ FIREWORKS_API_KEY = "dummy_token_for_testing"
67
 
68
  if not BRAVE_SEARCH_API_KEY:
69
  logger.warning("BRAVE_SEARCH_API_KEY not set. Web search features will be disabled.")
 
379
  class WebNovelSystem:
380
  """Web novel generation system"""
381
  def __init__(self):
382
+ self.api_key = FIREWORKS_API_KEY
383
  self.api_url = API_URL
384
  self.model_id = MODEL_ID
385
  self.tracker = WebNovelTracker()
 
387
  WebNovelDatabase.init_db()
388
 
389
  def create_headers(self):
390
+ return {
391
+ "Accept": "application/json",
392
+ "Content-Type": "application/json",
393
+ "Authorization": f"Bearer {self.api_key}"
394
+ }
395
 
396
  # --- Prompt generation functions ---
397
  def create_planning_prompt(self, query: str, genre: str, language: str) -> str:
 
667
  "model": self.model_id,
668
  "messages": full_messages,
669
  "max_tokens": max_tokens,
670
+ "temperature": 0.6,
671
+ "top_p": 1,
672
+ "top_k": 40,
673
+ "presence_penalty": 0,
674
+ "frequency_penalty": 0,
675
  "stream": True
676
  }
677
 
 
1851
 
1852
  # Environment check
1853
  logger.info(f"API Endpoint: {API_URL}")
1854
+ logger.info(f"Model: {MODEL_ID}")
1855
  logger.info(f"Target: {TARGET_EPISODES} episodes, {TARGET_WORDS:,} words")
1856
  logger.info("Genres: " + ", ".join(WEBNOVEL_GENRES.keys()))
1857
 
 
1868
  server_name="0.0.0.0",
1869
  server_port=7860,
1870
  share=False
1871
+ )