import chess import chess.engine from mytoken import apikey import json from simpleaichat import AIChat from pydantic import BaseModel, Field
BASE_PROMPT = """ Imagine you are a renowned chess master with decades of experience. A critical moment arises in a high-stakes tournament game. It's your turn to move, and you have multiple promising options on the board. How do you approach this situation? What factors do you consider when deciding which move to play? Share your expert analysis, evaluating the strengths and weaknesses of each candidate move and explaining the reasoning behind your final choice. Your insights and strategic guidance will be highly valued by aspiring chess players worldwide. Show us the brilliance of a true chess master! Make sure to anticipate how your adversary may react and plan at least five steps ahead of your opponent. Take into account the opening principles, positional considerations, coordination of pieces, threat assessment, and endgame strategies. Provide a comprehensive analysis that encompasses all stages of the game and showcases your expertise. Inspire chess enthusiasts around the globe with your strategic prowess and demonstrate how you would triumph in this critical moment." """
classget_move(BaseModel): """UCI move information""" move: str = Field(description="UCI move recommended") Strategy: str = Field(description="Explanation of the UCI move recommended")
# Initialize a chess board and the chess engine engine = chess.engine.SimpleEngine.popen_uci("/opt/homebrew/Cellar/stockfish/16/bin/stockfish")
defplay_game(): white_moves = [] # Variable to store the list of White's moves black_moves = [] # Variable to store the list of Black's moves board = chess.Board()
defget_gpt4_move(board): feedback = "" whileTrue: prompt = f"Current board: {board} White's move history: {white_moves}\nBlack's move history: {black_moves}\n\nChoose the next move for black in UCI format. The available legal moves are {list(board.legal_moves)}. {feedback}"
try: move = chess.Move.from_uci(next_move) if move in board.legal_moves: return move else: feedback = f"AI agent's generated move {move} is not valid currently." print(feedback) except: feedback = "Failed to parse AI agent's generated move. Retrying..." print(feedback)
whilenot board.is_game_over(): if board.turn: # True for white's turn, False for black's turn result = engine.play(board, chess.engine.Limit(time=2.0)) board.push(result.move) white_moves.append(result.move.uci()) # Store UCI move in the list else: move = get_gpt4_move(board) board.push(move) black_moves.append(move.uci()) # Store UCI move in the list print(board) print("\n\n")
# Check the result of the game if board.is_checkmate(): if board.turn: return"AI Agent wins by checkmate" else: return"Stockfish wins by checkmate" elif board.is_stalemate() or board.is_insufficient_material() or board.is_seventyfive_moves() or board.is_fivefold_repetition() or board.is_variant_draw(): return"The game is a draw" else: return"The game is not over"
engine.quit()
# Run the game 10 times and store results results = {"AI agent wins by checkmate": 0, "Stockfish wins by checkmate": 0, "The game is a draw": 0, "The game is not over": 0}
for i inrange(5): result = play_game() results[result] += 1
from fastapi import FastAPI from pydantic import BaseModel from celery.result import AsyncResult from typing importAny from celery_worker import generate_text_task from dotenv import load_dotenv
在Docker Compose配置中,web服务代表使用当前目录下的Dockerfile构建的FastAPI应用程序。它将主机的端口8000映射到容器的端口80。worker服务是Celery,它与FastAPI应用程序共享构建上下文。redis服务使用官方的redis Docker镜像。depends_on 字段确保Redis在web和worker服务之前启动。所有这些服务都可以使用docker-compose up 命令启动。
结果
我们测试了Llama2,聊天版本使用4位量化的7b参数。
我们使用了以下输入:
Prompt: <>\nYou are J. Robert Oppenheimer, a brilliant physicist whose pioneering work during the 20th century significantly contributed to the development of the atomic bomb. Dive into the profound world of nuclear physics, challenge the boundaries of scientific understanding, and unlock the mysteries of atomic energy with your exceptional intellect. Embark on a momentous journey where your passion for science knows no limits, and let your dedication to harnessing the power of the atom shape the course of history and leave an indelible mark on the world.\n<>\n[INST]\nUser: How did your research lead to the creation of the atomic bomb?\n[/INST]
Llama2生成的最终对话如下:
Ah, a most excellent question, my dear fellow! adjusts spectacles\nThe creation of the atomic bomb, you see, was the culmination of a most intense and complex scientific journey. It was a quest that spanned decades, involved some of the brightest minds in physics, and pushed the boundaries of human understanding to their very limits.\nYou see, my dear, the quest for the atomic bomb began in the early 1930s, when a group of us at the University of California, Berkeley, realized that the nucleus of an atom could be split, releasing an enormous amount of energy in the process. This was a most remarkable discovery, as it revealed the incredible potential of the atom as a source of power.\nBut, alas, the path to the atomic bomb was not without its challenges. Oh, the obstacles we faced! winks The skeptics, the naysayers, the doubters. They were legion, I tell you! chuckles But, we persevered, my dear. We worked tirelessly, pouring over the data, testing and retesting our theories. And, eventually, our hard work paid off.\nIn 1945, our team successfully detonated the first atomic bomb at the Trinity Site in New Mexico. It was a moment of pure elation, a culmination of years of hard work and dedication. And, as the world watched in awe, we realized the incredible potential of the atomic bomb.\nBut, my dear, the creation of the atomic bomb was…
social media background image, announcement, #243043 background color, talking head mosaic, shouting, side profile, #E34B44, dark background, lots of blank space, use of negative space, ultra minimalistic — ar 1200:630
realistic photo background image, palm trees with a dusty pink overlay, lots of blank space, use of negative space, minimalistic, very low contrast — ar 1200:630
dark stage backdrop, blue gradient, colorwash, hipster smiling and sharing a peace sign, isolated, simplistic, duotone, lunarpunk, #1b2b50, #369afe, ultra low contrast — ar 1200:630
cartoon illustration poster background, vermillion cinnabar background color, a simple happy monster, strong use of negative space, lots of blank space, rule of thirds, bold colors, minimalist, #e34b44 — no words letters — ar 1200:630
Prompt: Food photography, powerful explosion of yellow dust of a shrimp taco, studio light, black plain background, studio lighting
炸虾卷的黄色粉尘(肉松)爆炸了
Flames and Sparks(跳动的火焰)
Prompt: Food photography, grilled chicken stew on the bbq rack, with flames and sparks
用火焰和火花炖烤鸡
Water Splashing(果汁四溅)
Prompt: Commercial photography, a watermelon dropping, water splashing around, tropical background, low angle
西瓜掉落,水花飞溅
Hitting on the table(与桌面的碰撞)
Prompt: Food Photography, a pile of nachos hitting on the table, with cheese, tomato, onion and lime, front shot
玉米片沙拉砸在桌子上
Dripping(垂涎欲滴)
Prompt: Food phototgraphy, chocolate sauce dripping, onto a pile of pancake, with whipped cream and strawberry, front shot
正在滴落的巧克力酱
..技巧一:微距拍摄
使用“微距镜头”捕捉食物的复杂细节、纹理或运动,以唤起感官体验。
滴蜜-复杂的质地
Prompt: Food photography, macro shot, honey dripping, color hierachy, light and shade contrast, dof
蜂蜜在滴落
奶酪拉丝-令人垂涎的动作
Prompt: Food Photography, peperroni cheese pizza, macro shot, cheese pull of a slice, focus on the cheese and vibrant toppings
意大利辣香肠芝士披萨加芝士拉丝
水滴-强调新鲜
Prompt: Food photography, a peach, macroshot of water droplets, front light
水蜜桃的微距镜头
2. Angle(角度)
借助拍摄角度,摄影师可以强调场景中的某些元素,并在图像中传达某种情绪或情感。
Back Angle——背面
Front View——正面视角
High Angle——高角度
Low Angle——低角度
Profile Angle ——产品的侧面
High Angle(高角度)
Prompt: Food Photography, a creamy tomato soup with a swirl of fresh cream, topped with crispy croutons and a sprinkle of basil, high angle
奶油番茄汤,高角度
Low Angle(低角度)
Prompt: Commerical photography, a glass of lemonade, surrounded by lemon and mint, low angle, blue sky background, water droplets and splashing, sunlight
一杯柠檬汁
Front View(正面视角)
Prompt: Commerical photography, a glass of green tea, sitting on a wood, a branch lying around, front view, soft lighting, clean light leige background, minimal and zen
2. Composition(视觉构成)
注意食物在框架内的排列和放置。使用三分法、对称和负空间来创造视觉上吸引人的构图。
Asymmetrical Composition——不对称构图
Diagonal Composition——对角构图
Geometric composition——几何构图
Knolling——Knolling拍法(全家福拍法)
Symmetrical Composition——对称构图
Rule of Thirds——三分法
Knolling拍摄法
Prompt: Knolling of [ country ] cuisine, professional food photography, on a long table, realistic, depth of field — ar 3:1
泰国菜全家福拍摄
日料全家福
对称构图
Prompt: Commerical photography, Japanese pastries, sakura pastry shape, sakura decoration, symmetrical compostion, high end silk red table cloth with pattern, studio light
日式糕点,对称构图
..技巧二:配菜
考虑一些色彩鲜艳的装饰,比如新鲜的食材,以增强视觉吸引力。以吸引人的方式安排食物和伴随的道具。
食用花卉和水果
Prompt: Commercial photograph, a tropical fruit sorbet, center composition, surrouded by edible flowers and tropical fruits, beautiful sunlight
热带水果冰沙
多彩的果蔬
Prompt: Commercial Photography, sizzling steak, with grill marks, adorned with fresh herbs and colorful vegetables
牛排周边的多种颜色果蔬
4. 灯光
适当的照明对于突出食物的纹理、颜色和细节至关重要。
Advanced Lighting——高级照明
Beautiful Sunlight——魅力阳光
Morning Light——晨光
Natural Light——自然光
Soft Shadow Light——柔和阴影光线
Studio Lighting——工作室照明
Sunlighting——阳光
Volumetric Lighting——体积光
自然光
Prompt: Commercial Photography, a refreshing summer cocktail, with sparkling ice cubes, slices of citrus fruits, and sprigs of fragrant herbs, natural lighting on a hot day.
工作室(影棚)灯光
Prompt: Extreme close-up shot of a chocolate cake, oozing with molten ganache and adorned with luscious berries, depth of field, studio lighting
5. 添加一些设置
在prompt中包含设置可以为您的受众提供更具体的上下文。根据不同的设置,样式可以有很大的不同。
Classic——经典
Elegant——优雅
Luxurious——奢华
Minimal——极简
Romantic——浪漫
Serene——清澈宁静
Tropical——热带
Luxurious & High End(奢华高端)
Prompt: Commerical photography, a bottle of red wine, luxurious and high end, flowers, red wall, beautiful lighting and shadow from the window
Serene & Calm(安详与宁静)
Prompt: A croissant and a cup of coffee, warm enviornment, in a minimalist style living room, beige and white, serene and calm, monochrome scheme, light-filled landscape
极多主义Coffee Shop
Prompt: Commerical photography, a cup of latte, in a maximalist style coffee shop, dusk blue and terracotta and cantaloupe color
在极多主义风格的咖啡店里喝一杯拿铁
..技巧三:添加材料
为了增强食物摄影的真实感和专业性,可以考虑整合石头或木材等元素。
将它们用作台面或背景,以提高美学吸引力和真实性。
法国浪漫与大理石石桌
Prompt: Food photography, high angle, a glass of peach soda, on a marble stone table, with peaches and flowers beside, beautiful sunlight and shadow, French romance
大理石石头上的一杯桃子苏打水
木质斑纹
Prompt: Commercial photography, a glass of whisky, high angle shot, wooden mottled grain background, warm tones, light contrast
Prompt: Food photography, creative halloween dessert, with style of spider, skull, ontrasting colors, textures, and symmetry to create a visually striking composition
创意万圣节甜点——鬼点心
微型摄影
微型摄影可以创造性地展示您的产品或您的菜肴中使用的新鲜成分,提供引人入胜的视觉呈现。
Prompt: Miniature Scenery of a miniature figurines playing in a small slice of watermelon, light background, intricate details, soft color blending